Strings

Q1: What will be the output of the program ?
#include<stdio.h>

int main()
{
    char t;
    char *p1 = "India", *p2;
    p2=p1;
    p1 = "Aptitude";
    printf("%s %s\n", p1, p2);
    return 0;
}

A India Aptitude

B Aptitude India

C India India

D Aptitude Aptitude

ANS:B - Aptitude India

Step 1: char *p1 = "India", *p2; The variable p1 and p2 is declared as an pointer to a character value and p1 is assigned with a value "India". Step 2: p2=p1; The value of p1 is assigned to variable p2. So p2 contains "India". Step 3: p1 = "Aptitude"; The p1 is assigned with a string "Aptitude" Step 4: printf("%s %s\n", p1, p2); It prints the value of p1 and p2. Hence the output of the program is "Aptitude India".



img not found
img

For help Students Orientation
Mcqs Questions

One stop destination for examination, preparation, recruitment, and more. Specially designed online test to solve all your preparation worries. Go wherever you want to and practice whenever you want, using the online test platform.