0% found this document useful (0 votes)
110 views3 pages

C MCQ

This document contains 14 code snippets with C programming concepts like printf formatting, string manipulation, character access, macro pre-processing, and operator precedence. Each snippet is followed by the expected output. Some key points summarized: 1) scanf returns the number of inputs read successfully 2) printf formatting like %s, %c, %d can access characters in a string by index or print substrings 3) Macro definitions use #if/#else to conditionally set values 4) Operator precedence and order of evaluation determine the behavior of expressions passed to printf

Uploaded by

Franklin Salvius
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
110 views3 pages

C MCQ

This document contains 14 code snippets with C programming concepts like printf formatting, string manipulation, character access, macro pre-processing, and operator precedence. Each snippet is followed by the expected output. Some key points summarized: 1) scanf returns the number of inputs read successfully 2) printf formatting like %s, %c, %d can access characters in a string by index or print substrings 3) Macro definitions use #if/#else to conditionally set values 4) Operator precedence and order of evaluation determine the behavior of expressions passed to printf

Uploaded by

Franklin Salvius
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 3

1)

#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

NOTE:printf() returns the number of characters


successfully printed on the screen.

11)
#include "stdio.h"
int main()
{
int a = 10;
int b = 15;

printf("=%d",(a+1),(b=a+2));
printf(" %d=",b);

return 0;
}

ans: =11 12=


NOTE:
As per C standard C11, all the arguments of printf() are evaluated irrespective of
whether they get printed or not. That’s why (b=a+2) would also be evaluated and
value of b would be 12 after first printf()

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)

You might also like