C Programming - Strings - Discussion
Discussion Forum : Strings - Find Output of Program (Q.No. 2)
2.
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;
}
Answer: Option
Explanation:
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'.
Discussion:
12 comments Page 2 of 2.
Anu Sri said:
1 decade ago
How can array 'p' become "%c" ?
PRAMOD KUMAR said:
9 years ago
ASCII table remember.
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers