Discussion
Consider the following ‘C’ fragment of code where a, b, c is given as input then predict the output from the following :
. . .
char x, y, z;
printf (‘‘%d’’, scanf (‘‘%c%c%c’’, &x, &y, &z));
Answer: D
The program shows 3 at output.
The inner call scanf("%c%c%c", &x, &y, &z) is evaluated first. It reads three characters from the input into x, y and z. scanf returns the number of input items successfully assigned, which is 3. That return value is then the argument of printf with the %d format, so printf prints 3.
The code is valid C, so there is no syntax error, and the arguments are proper addresses of char variables, so there is no fatal error or segmentation violation. Whatever characters are typed, three successful %c conversions give 3.
Post your comment
Please log in or register to post a comment.
Examination Categories
- SSC Exams
- Banking Exams
- Teaching Exams
- Civil Services Exams
- Railways Exams
- Engineering Recruitment Exams
- Defence Exams
- State Government Exams
- Police Exams
- Insurance Exams
- Nursing Exams
- Other Government Exams
- NRA CET
- PG Entrance Exams
- Campus Placement
- MBA Entrance Exams
- CUET and UG Entrance
- Judiciary Exams
- Regulatory Body Exams
- Software Development