Printf & Scanf C Programming MCQ Questions
Printf & Scanf C Programming MCQ of the C programming. These Multiple Choice Questions (MCQ) should be practiced to improve the C programming skills required for various interviews (campus interview, walk-in interview, company interview), placement, entrance exam, and other competitive examinations.
What is the output of this program?
#include <stdio.h> int main() { printf("variable! %d", x); return 0; }
A. variable! x
B. variable! followed by a junk value
C. Compile time error
D. variable!
It will give compile time error since x is not declared.
What is the output of this program?
#include <stdio.h> int main() { int main = 3; printf("%d", main); return 0; }
A. 3
B. Compile time error
C. Run time error
D. give garbage value
A C program can have same function name and same variable name.
What is the output of this program? if input a is 1 and b is 2
#include <stdio.h> int main() { int a, b; printf("%d", scanf("%d %d",&a,&b)); return 0; }
A. 1
B. 2
C. runtime error
D. compile time error
In C, scanf returns the number of inputs it has successfully read.
What is the output of this program?
#include <stdio.h> void main() { printf("hello\rworld\n"); printf("hello\b\b\bworld\n"); }
A. hello
helloworld
B. world
heworld
C. helloworld
hellold
D. None of the mentioned
“” for a backspace, means if u print it, cursor will print and come back 1 character . ‘ ‘ is used for carriage return to come 1 line back or in start of line.
What is the output of this program?
#include <stdio.h> int main() { int i; i = printf("letsfindcourse"); i = printf("%d ", i); printf("%d ", i); return 0; }
A. letsfindcourse 15 3
B. letsfindcourse 14 2
C. letsfindcourse 14 3
D. Compilation Error
In C, printf() returns the number of characters successfully written on the output. Here letsfindcourse contain 14 character therefore i = 14 and then i is printed now again value of printf is assign but this time it print 3 since it contain 3 character %,d and space.
Output of this statment is :
printf ( "%d" , printf ( "hello" ) );
A. Syntex Error
B. hello5
C. gives garbage value
D. print hello and terminates
In C, printf() returns the number of characters successfully written on the output. Here letsfindcourse contain 14 character therefore i = 14 and then i is printed now again value of printf is assign but this time it print 3 since it contain 3 character %,d and space.
What is the output of this program?
#include <stdio.h> # define scanf "%s Find best course " main() { printf(scanf, scanf); return 0; }
A. %s Find best course Find best course
B. %s Find best course %s Find best course
C. Invalid Syntex
D. Run time error
printf statement will become printf(“%s Find best course “, “%s Find best course “);
Which statment is true about the given code ?
#include <stdio.h> int main() { printf("%d", main); return 0; }
A. Goes in infinite loop
B. Gives Address of function main.
C. Gives garbage value
D. Compilation Error
Name of the function is actually a pointer variable to the function and prints the address of the function.
What is the output of this program?
#include <stdio.h> int main() { int i; i = 1, 2, 3; printf("%d", i); return 0; }
A. 1
B. 2
C. 3
D. Invalid Syntax
Associativity of comma operator is from left to right, but = operator has higher precedence than comma operator.Therefore the statement i = 1, 2, 3 is treated as i = 1 .
Comment on the given statment:
scanf("%d",i);
A. Will execute without any error
B. Will give Segmentation fault
C. Will give Compilation Error
D. None of the above
A segmentation fault occurs when a program attempts to access a memory location that it is not allowed to access, or attempts to access a memory location in a way that is not allowed.So as we can see segmentation fault occurs because program attempts to access a memory location that it is not allowed to access.
What is the output of this program?
#include <stdio.h> int main() { int x = 1, y = 2; printf("%d", x, y); return 0; }
A. 1
B. 2
C. Compilation Error
D. Garbage Value
What is the output of this program?
#include <stdio.h> int main() { int x = 1, y = 2; printf("%*d", x, y); return 0; }
A. 1
B. 2
C. Compilation Error
D. Garbage Value
None
What is the output of this program?
#include <stdio.h> int main() { char str[25]; printf(" %d ",printf("c-letsfind")); return 0; }
A. 10 c-letsfind
B. 9 c-letsfind
C. c-letsfind 9
D. c-letsfind 10
Inner printf() will print first and then outer printf will display the length of the inner printf’s string.
What is the output of this program?
#include <stdio.h> # define loop while(true) int main() { loop; printf("c-letsfind"); return 0; }
A. program never ends
B. c-letsfind
C. Compilation error
D. None of the above
error: ‘true’ undeclared (first use in this function)
What is the output of this program ?
int main() { int i=-2; i=i+i*i++; printf("%d",i); return 0; }
A. -2
B. 1
C. -1
D. -2
What is the output of this program ?
int main() { int a=250; printf("%1d<0x1d>", a); return 0; }
A. 1250
B. 2
C. 50
D. 250
int a=250; The variable a is declared as an integer type and initialized to value 250. printf(“%1d<0x1d> “, a); It prints the value of variable a. Hence the output of the program is 250.