Please Turn On Java Script To Access This Site.

C Institute | Questions


Previous Topic : Conditional Operator - 2Next Topic : sizeof operator - 2

This section focuses on C interview questions, tricky questions, and puzzles, and viva questions based on “sizeof operator”. One shall practice these questions and puzzles to improve their C programming skills needed for various interviews (campus interviews, walk-in interviews, viva exams and company interviews), placements, entrance exams and other competitive exams.
These programming questions can be attempted by anyone focusing on learning C Programming language. They can be a beginner, fresher, engineering graduate, engineering student, bca student, mca student, mcs students or an experienced IT professional. It will improve their understanding of C Language.
Here is a listing of C questions and puzzles on “sizeof operator” along with answers and/or explanations.

Q1: sizeof is a _____ operator.
a)  Ternary
b)  Unary
c)  Binary
d)  None of these
Correct Answer : b
Explanation : sizeof is a unary operator, because it requires a single operand.


Q2: What will be the output of the following code?
#include<stdio.h>
int main()
{
int a=10,b=20;
printf("%d %d",sizeof(a+=b),b);
return 0;
}
a)  2 30
b)  4 30
c)  4 20
d)  2 20
Correct Answer : c
Explanation : Any assignment operation or function call does not work inside the parenthesis of sizeof operators.
Learn size of operator in depth


Q3: Which of the following is not an operator in C?
a)  !
b)  ^
c)  ~
d)  None of the above
Correct Answer : d


Q4: Which among the following is never possible in C when members in a structure are same as that in a union?

//Let A be a structure
//Let B be a union
a)  sizeof B is greater than sizeof A
b)  sizeof B is less than sizeof A
c)  sizeof B is equals to the sizeof A
d)  None of these
Correct Answer : a


Q5: What will be the output of the following code?
#include <stdio.h>
int main()
{   printf("%d ",sizeof(0.0+0.0f));
    return 0;
}
a)  0
b)  4
c)  8
d)  12
Correct Answer : c
Explanation : As we know tha when sizeof() is used with the expression, it returns size of the expression. As we know that 0.0 is double and 0.of is float so there addition will produce double value. And sizeof double is 8 bytes, so sizeof will return 8.


Q6: if size of an integer is 4 byte. What is the output of program?
#include <stdio.h> 
int main() 
{   int a = 15, b = 20, c = 100; 
    printf("%d ", sizeof(c /= a + b)); 
    printf("%d", c); 
    return 0; 
} 
a)  4 2
b)  4 26
c)  4 100
d)  4 20
Correct Answer : c
Explanation : sizeof(c /= a + b). An expression doesn’t get evaluated inside sizeof operator. sizeof operator returns sizeof(int) because the result of expression will be an integer. As the expression is not evaluated, value of c will not be changed.


Q7: What will be the output, assume that sizeof int type is 2 bytes?
#include <stdio.h>
int main()
{   int i = 12;
    int j = sizeof(i++);
    printf("%d  %d", i, j);
    return 0;
}
a)  13 2
b)  12 2
c)  12 12
d)  12 13
Correct Answer : b
Explanation : The size of will give size of int, that is assumed 2 bytes, so ji is 2. Any expression inside the parenthesis of sizeof is not evaluated, so i remains 12.


Previous Topic : Conditional Operator - 2Next Topic : sizeof operator - 2