C MCQ
C MCQ
#include "stdio.h"
int main()
{
char arr[100];
printf("%d", scanf("%s", arr));
/* Suppose that input value given
for above scanf is frank" */
return 1;
}
answer: 1
In C, scanf returns the no. of inputs it has successfully read
2)
#include <stdio.h>
int main()
{
printf("GEEKS %% FOR %% GEEKS");
return 0;
}
ans:GEEKS % FOR % GEEKS
3)
#include <stdio.h>
int main()
{
printf("\"GEEKS %% FOR %% GEEKS\"");
return 0;
}
ans:“GEEKS % FOR % GEEKS”
4)
#include <stdio.h>
// Assume base address of "GeeksQuiz" to be 1000
int main()
{
printf(5 + "GeeksQuiz");
return 0;
}
ans: quiz
5)
#include <stdio.h>
int main()
{
printf("%c ", 5["GeeksQuiz"]);
return 0;
}
ans: Q
6)
#include <stdio.h>
int main()
{
printf("%c ", "GeeksQuiz"[5]);
return 0;
}
ans: Q
7)
What does the following C statement mean?
scanf("%4s", str);
ans:Read maximum 4 characters from console.
8)
#include<stdio.h>
int main()
{
char *s = "Geeks Quiz";
int n = 7;
printf("%.*s", n, s);
return 0;
}
ans: Geeks Q
9)
#include <stdio.h>
int main(void)
{
int x = printf("GeeksQuiz");
printf("%d", x);
return 0;
}
ans:geeksquiz9
10)
#include<stdio.h>
int main()
{
printf("%d", printf("%d", 1234));
return 0;
}
ans:12344
11)
#include "stdio.h"
int main()
{
int a = 10;
int b = 15;
printf("=%d",(a+1),(b=a+2));
printf(" %d=",b);
return 0;
}
12)
main ( )
{
int x = 128;
printf (“\n%d”, 1 + x ++);
}
ans:129
In the following C program There is post increment operation: So, printf will print
1 + 128 as output. ++ will increment the x value i.e. x = 129
13)
#include <stdio.h>
#if X == 3
#define Y 3
#else
#define Y 5
#endif
int main()
{
printf("%d", Y);
return 0;
}
ans: 5
NOTE:
In the first look, the output seems to be compile-time error because macro X has
not been defined. In C, if a macro is not defined, the pre-processor assigns 0 to
it by default. Hence, the control goes to the conditional else part and 5 is
printed.
14)