What is sizeof() in C MCQ

What is sizeof() in C MCQ? Quiz on Sizeof Function in C | The size of data types is dependent on the compiler or you can say that the system architecture i.e. 32-bit compiler or 64-bit compiler. All the below programs are tested using a 64-bit machine and GCC compiler, (nowadays most of the computers are 64-bit).

The operator sizeof() is a unary compile-time operator that returns the length, in bytes, of the variable or parenthesized type-specifier that it precedes.

Recommended Reading:- Size and Range of data types in C, Operators in C

Sizeof Function Quiz C

Find the output of the programs given in Quiz on Sizeof Function in C?

Q1) Find the output of the given C program.

#include<stdio.h>
int main()
{
  printf("%ld",sizeof(100));
  return 0;
}

a) 12
b) 8
c) 4
d) 10


Ans:- c) 4


Q2) Find the output of the given C program.

#include<stdio.h>
int main()
{
  printf("%ld",sizeof(40000u));
  return 0;
}

a) 4
b) 10
c) 8
d) 12


Ans:- a) 4


Q3) Find the output of the given C program.

#include<stdio.h>
int main()
{
  printf("%ld",sizeof(1.2));
  return 0;
}

a) 12
b) 10
c) 8
d) 4


Ans:- c) 8

By default, every floating-point number is treated as a double data type by the compiler.


Q4) Find the output of the given C program.

#include<stdio.h>
int main()
{
  printf("%ld",sizeof(9.5f));
  return 0;
}

a) 10
b) 4
c) 8
d) 12


Ans:- b) 4

It adds suffix F or f to any number then its data type becomes a float.


Q5) Find the output of the given C program.

#include<stdio.h>
int main()
{
  printf("%ld",sizeof(1213.2L));
  return 0;
}

a) 16
b) 8
c) 4
d) 10


Ans:- a) 16

Here 1213.2L is of a long double data type.


Q6) Find the output of the given C program.

#include<stdio.h>
int main()
{
  printf("%ld",sizeof('a'));
  return 0;
}

a) 4
b) 1
c) 8
d) 2


Ans:- a) 4

Here ‘a’ is not treated as a char data type, it will directly convert to 97 and treated as an int data type. So, the size of(‘a’) is the same as the size of(int).


Q7) Find the output of the given C program.

#include<stdio.h>
int main()
{
  char ch = 'a';
  printf("%ld",sizeof(ch));
  return 0;
}

a) 1
b) 2
c) 8
d) 4


Ans:- a) 1

This time ‘a’ is considered as char data type and the size of char data type is 1 byte.


Q8) Find the output of the given C program.

#include<stdio.h>
int main()
{
  printf("%ld",sizeof("a"));
  return 0;
}

a) 2
b) 4
c) 1
d) 8


Ans:- a) 2

In this program “a” is a string. And its size is two bytes. One byte for the character ‘a’ and one byte for ‘\0’


Q9) Find the output of the given C program.

#include<stdio.h>
int main()
{
  printf("%ld",sizeof("1000"));
  return 0;
}

a) 5
b) 1
c) 4
d) 2


Ans:- a) 5

In this program “1000” is not an integer number, it is a string. So, four bytes for 1,0,0,0 and one byte for ‘\0’ Hence total 5 bytes.


Q10) Find the output of the given C program.

#include<stdio.h>
int main()
{
  char ch[10]="abc";
  printf("%ld",sizeof(ch));
  return 0;
}

a) 10
b) 12
c) 4
d) 8


Ans:- a) 10

When we declare an array of 10 char data type then 10 bytes of memory is provided. First three bytes are filled with a,b,c and remaining all bytes filled with null (‘\0’)


Q11) Find the output of the given C program.

#include<stdio.h>
int main()
{
  char ch[]="abc";
  printf("%ld",sizeof(ch));
  return 0;
}

a) 8
b) 10
c) 12
d) 4


Ans:- d) 4

Here we don’t declare the size of char array at the time of initialization so only 4 bytes of memory will be provided. First three bytes for a, b, c and one byte for ‘\0’


Q12) Find the output of the given C program.

#include<stdio.h>
int main()
{
  char ch[]={'a','b','c'};
  printf("%ld",sizeof(ch));
  return 0;
}

a) 10
b) 2
c) 4
d) 3


Ans:- d) 3

Each character is stored in a contiguous memory location. No, any null character will be stored. So, only three bytes of memory will be allocated. Sending character by character so there is no scope for the null character.


Q13) Find the output of the given C program.

#include<stdio.h>
int main()
{
  char ch[10]={'a','b','c'};
  printf("%ld",sizeof(ch));
  return 0;
}

a) 10
b) 4
c) 2
d) 3


Ans:- a) 10

In this program first, 10 bytes of memory is allocated to store char data type. After that first three space filled by ‘a’, ‘b’ and ‘c’ remaining all spaces filled by ‘\0’


Q14) Find the output of the given C program.

#include<stdio.h>
int main()
{
  int a=2;
  printf("%ld ",sizeof(a+3));
  printf("%ld ",sizeof a+3);
  return 0;
}

a) Compile time error
b) 44
c) 47
d) None of these


Ans:- c) 47

The expression sizeof a+3 evaluated as sizeof(a) + 3.


If you enjoyed this post, share it with your friends. Do you want to share more information about the topic discussed above or you find anything incorrect? Let us know in the comments. Thank you!

Leave a Comment

Your email address will not be published. Required fields are marked *