General C MCQs
Start
Congratulations - you have completed General C MCQs.
You scored %%SCORE%% out of %%TOTAL%%.
Your performance has been rated as %%RATING%%
Thanks for visiting at BloggingSimplified.in!!
Your answers are highlighted below.
Question 1 |
Identify 4 invalid identifiers?
A | _sum |
B | 7sum |
C | S_num |
D | s num |
E | s-num1 |
F | int |
Question 1 Explanation:
Identifier cannot start with a digit,
cannot have a space in between &
- is an invalid use in identifier.
Question 2 |
Tell the output of the following C Code?
int _=5; int __=10; int ___= _ + __; printf("%d",___);
A | 5 |
B | 10 |
C | 15 |
D | Compile Time Error |
Question 2 Explanation:
_ can be used as identifier.
Question 3 |
Tell the output for following query:
int main = 10; printf("%d",main);
A | 10 |
B | Compile Time Error |
C | Run Time Error |
D | Depends on compiler |
Question 3 Explanation:
main is not a keyword but an identifier.
Question 4 |
Tell the output of following query:
int a=10,b=20; printf("%d %d",100);
A | 10 20 |
B | 20 10 |
C | 100 Garbage value |
D | Compile Time Error |
Question 4 Explanation:
It is clear that the second %d has no value to be picked and displays garbage value.
Question 5 |
Tell the output for following query:
printf("abc" "def");
A | abc |
B | def |
C | abcdef |
D | Compile Time error |
Question 6 |
Tell the output for the following query:
a=10; printf(2+"GoodBye!"); printf(1+"%d"); printf(1+"%c"); printf(1+"%d%d",a);
A | odByedcd10 |
B | Goodbye Garbage Value Garbage Value 10 Garbage Value |
C | Compile Time Error |
Question 6 Explanation:
Adding 2+ before printf commas omits the first 2 characters inside the commas.
Question 7 |
Tell the output for the following query:
printf(2+"%d%%d Welcome");
A | Garbage value |
B | It prints "%d Welcome" [without ""] |
C | Compile Time error |
Question 8 |
Tell the output for the following query:
int n=(10,20,30); printf("%d",n);
A | 10 |
B | 20 |
C | 30 |
D | Compile time error |
Question 9 |
Tell the output for the following query:
int a,b,c,num; num=scanf("%d %d %d",&a,&b,&c); printf("%d ",num); num=printf("%d%d%d",a,b,c); printf("%d",num);
A | 6 6 |
B | 3 6 |
C | 10 6 |
D | Compile Time Error |
Question 9 Explanation:
Scanf returns the number of items scanned (In the above example it returns 3 numbers)
Printf returns the number of characters entered (In the above example - %d%d%d=6 Characters )
Question 10 |
Tell the output of following query:
int a=0673; a=a+1; printf("%d",a);
A | 0673 |
B | 0674 |
C | 443 |
D | 444 |
E | Compile Time Error |
Question 10 Explanation:
Adding a 0 infront of integer defines the number to be octal.
Conversion of 673 in decimal = (3*1) + (7*8) + (6*64)=443
and we added a statement a=a+1, this implies a=443+1=444.
Question 11 |
Tell the output of following query:
printf("Hard", "Work");
A | Hard |
B | Work |
C | Hard Work |
D | Compile Time Error |
Question 12 |
a=1; b=23; printf("%2d%3d",a,b);
A | 123 |
B | _1_23 Hint: _ means a space. |
C | 1_23 Hint: _ means a space. |
D | __1___23 Hint: _ means a space. |
Question 12 Explanation:
%2d means the expression should contain 2 characters, if it has 1 character then add a space infront of the character and same for %3d.
Question 13 |
int i=0,j; j=(i+1,i+=2,i+3); printf("i=%d j=%d",i,j);
A | i=0 j=0 |
B | i=2 j=5 |
C | i=2 j=3 |
D | i=2 j=4 |
Question 13 Explanation:
Since the execution inside brackets takes place from left to right, all statements inside brackets are executed but
only one out of all the statements changes the value of i.
That is i+=2 changes the value of i from 0 to 2.
And finally j picks the value of i+3=2+3=5.
Question 14 |
int m=1; int n; n=(m=m+3,m%3); printf("%d %d",m,n);
A | 1 1 |
B | 4 1 |
C | 3 1 |
D | 2 1 |
Question 14 Explanation:
Since the execution inside brackets takes place from left to right, all statements inside brackets are executed but
only one out of all the statements changes the value of m.
That is m=m+3 changes the value of m from 1 to 4.
And finally n = m%3=4%3=1.
Question 15 |
int i=0,j; j=(i+1,i+=2,i+3); printf("i=%d j=%d",i,j);
A | i=0 j=3 |
B | i=2 j=3 |
C | i=2 j=5 |
D | i=0 j=0 |
Question 15 Explanation:
Since the execution inside brackets takes place from left to right, all statements inside brackets are executed but
only one out of all the statements changes the value of i.
That is i+=2 changes the value of i from 0 to 2.
And finally j = i+3=2+3=5.
Question 16 |
scanf("%2d%3d%4d",&a,&b,&c); [Assume I/P as a=12, b=1234 & c=12345] printf("%d%d%d",a,b,c);
A | 12 1234 12345 |
B | 12 123 1234 |
C | 12 12 12 |
D | 123 123 123 |
Question 16 Explanation:
While scanning if we add an integer after %, only that number of characters will be passed to the variable.
For example:
for %3d -> 3 characters will be scanned
If we I/P 1234 for %3d then only 123 will be picked.
Question 17 |
float a=2.5; printf("%.3f",a);
A | 2.5 |
B | 2.500000 |
C | 2.500 |
D | 2 |
Question 17 Explanation:
.3 means only 3 characters will be displayed after the point
Question 18 |
float a=2.5; printf("%9f",a);
A | 2.5 |
B | 2.500000 |
C | _2.500000 Hint: _ means a space |
D | _ _ 2.500000 Hint: _ means a space |
Question 18 Explanation:
Here %9f specifies that 9 spaces will be shown without considering the number of characters of the number. So 9 spaces will be made - _ _ _ _ _ _ _ _ _ Now we have a=2.5 as float which is shown as 2.500000 while printing which consumes 8 characters so the first character is left as space and 8 characters are shown as: _ 2 . 5 0 0 0 0 0 1 2 3 4 5 6 7 8 9 = 9 characters.
Question 19 |
int a,b=4,c=8,d=2,e=4,f=2; a=b+c/d+e*f; printf("%d",a); a=(b+c)/d+e*f; printf("%d",a); a=b+c/((d+e)*f); printf("%d",a);
A | 16 16 4 Hint: Knowing that * & / have more precedence than + or - |
B | 16 14 14 Hint: Knowing that * & / have more precedence than + or - |
C | 16 14 4 Hint: Knowing that * & / have more precedence than + or - |
D | None of the above Hint: Knowing that * & / have more precedence than + or - |
Question 19 Explanation:
Precedence order.
Question 20 |
int a; a=printf("Good")+printf("Boy"); printf("%d",a);
A | 7 |
B | Good4 |
C | GoodBoy7 |
D | None of the above |
Question 20 Explanation:
Printf returns the number of characters printed & also prints those characters, so form the above statement GoodBoy will be printed while defining a & 7 will be printed when we print a.
Question 21 |
char c='A'; printf("%c",c+10);
A | J |
B | K |
C | L |
D | A |
Question 21 Explanation:
ASCII conversion.
Question 22 |
int a=1; printf("%d %d",++a,a++);
A | 2 2 |
B | 1 2 |
C | 3 2 |
D | 3 1 |
Question 22 Explanation:
Direction of execution inside printf takes place from right to left, this implies a++ will be executed first & then ++a.
a++ picks value 1 then ++a = ++2=3.
Question 23 |
int a=1,x; x=(++a,a++); printf("%d",x);
A | 1 |
B | 2 |
C | 3 |
D | 4 |
Question 23 Explanation:
Execution inside brackets takes place from left to right,
so ++a is executed first then a++ which implies a gets a value of 2.
Question 24 |
int a=1234; printf("%3d",a); printf("%5d",a);
A | 123 _1234 Hint: _ means a space |
B | 12341234 |
C | 1234123 |
D | 1234 _1234 Hint: _ means a space |
Question 24 Explanation:
Since a is already has a value of 1234 & is not scanned using %3d so it will retain the same value for %1d or %2d or %3d or %4d as 1234, but when we use %5d in printf then 1 space is included infront of 1234.
Hence the output is 1234_1234
Question 25 |
int a=10,b=15,c=3,x; x=(a>b)?(a>c?a:c):(b>c?b:c); printf("%d",x);
A | 15 |
B | 10 |
C | 3 |
D | None of the above. |
Question 25 Explanation:
? operator.
Question 26 |
int i=2; int j=i+(1,2,3,4,5); printf("%d",j);
A | 2 |
B | 5 |
C | 6 |
D | 7 |
Question 26 Explanation:
In brackets the last value is picked.
Question 27 |
int k=35; printf("%d%d%d",k==35,k=50,k>40);
A | 1 50 1 |
B | 1 50 0 |
C | 0 50 0 |
D | 0 50 1 |
Question 27 Explanation:
Since execution in printf takes place from right to left this implies first k>40 is executed which returns 0, then k=50 which returns 50, then k==35 is executed which returns 0 because from the previous statement k is assigned a value of 50.
Question 28 |
int c=2^3; printf("%d",c);
A | 0 |
B | 1 |
C | Compile Time Error |
D | None of the above |
Question 28 Explanation:
2^3 means 2 XOR 3 = 010 XOR 011 = 001 001 = 1 in decimal. Hence answer is 1.
Once you are finished, click the button below. Any items you have not completed will be marked incorrect.
Get Results
There are 28 questions to complete.
You have completed
questions
question
Your score is
Correct
Wrong
Partial-Credit
You have not finished your quiz. If you leave this page, your progress will be lost.
Correct Answer
You Selected
Not Attempted
Final Score on Quiz
Attempted Questions Correct
Attempted Questions Wrong
Questions Not Attempted
Total Questions on Quiz
Question Details
Results
Date
Score
Hint
Time allowed
minutes
seconds
Time used
Answer Choice(s) Selected
Question Text
All done
Need more practice!
Keep trying!
Not bad!
Good work!
Perfect!