Strings

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

int main()
{
    char p[] = "%d\n";
    p[1] = 'c';
    printf(p, 65);
    return 0;
}

A A

B a

C c

D 65

ANS:A - A

Step 1: char p[] = "%d\n"; The variable p is declared as an array of characters and initialized with string "%d". Step 2: p[1] = 'c'; Here, we overwrite the second element of array p by 'c'. So array p becomes "%c". Step 3: printf(p, 65); becomes printf("%c", 65); Therefore it prints the ASCII value of 65. The output is 'A'.



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.