C Technical Interview Questions – Datatypes

These C Technical Interview Questions-DatatYPES post providing basic, intermediate and Hard level examples in C data types. Practice of these examples make you good in C programming.


What is the Output of following Code?
#include<stdio.h>
void main()
{
short int a , b=10;
printf(“%d, %d”, a, b);
}

  1. 0,10
  2. 10,10
  3. Garbage Value , 10
  4. 10, Garbage value

Answer :

Ans : 3 ; In C language, local variables implicitly initializes with garbage values when we don’t initialize manually

What is the Output of following Code?
#include<stdio.h>
char ch ;
float f ;
void main()
{
printf(“%d, %f”, ch, f);
}

  1. null_character, 0.000000
  2. 0 , 0.0
  3. 0, 0.000000
  4. null_character , 0.0

Answer :

Ans : 3 ; NULL character corresponding integer value is 0 and default value of float is 0.000000

What is the Output of following Code?
#include<stdio.h>
void main()
{
short s = 65536 ;
printf(“%d , %u “, s, s);
}

  1. 0, 0
  2. 0, 65536
  3. 65535 , 0
  4. 0, 65535

Answer :

Ans : 1 ; In the signed short int range(-32768 to +32767), the value 65536 is equals to 0

What is the Output of following Code?
#include<stdio.h>
void main()
{
signed short s = 32770 ;
printf(“%d”,s);
}

  1. compiler error
  2. -32766
  3. 32770
  4. Value varies based on compiler

Answer :

Ans : 2 ; If we count 32770 value in signed short int range(-32768 to 32767), the value is equals to -32766

What is the Output of following Code?
#include<stdio.h>
void main()
{
signed short s = -32774 ;
printf(“%u”, s);
}

  1. 32762
  2. Compiler error
  3. -32762
  4. 32774

Answer :

Ans : 1 ; If we count -32774 value in signed short int range(-32768 to 32767), the value is equals to 32762

What is the Output of following Code?
#include<stdio.h>
void main()
{
unsigned short s = -3 ;
printf(“%u”,s+2);
}

  1. -1
  2. Compiler error
  3. 65535
  4. Depends on compiler

Answer :

Ans : 3 ; The value of -3 is equals to 65533 and we add +2 , then value become 65535

What is the Output of following Code?
#include<stdio.h>
void main()
{
signed char ch = 256 + 65 ;
printf(“%c”,ch);
}

  1. Garbage character
  2. A
  3. Compiler error
  4. None of the above

Answer :

Ans : 2 ; In signed character limits, the value of 256 is equals to 0, hence the value 65 corresponding character is ‘A’

What is output of following program?
#include<stdio.h>
void main()
{
printf(“%d%d\b\b%d”,1,2,3);
}

  1. 123
  2. 312
  3. 3
  4. 321

Answer :

Ans : 3 ; After printing 1 and 2 , two back space characters erases printed values and finally 3 prints

What is output of following program?
#include<stdio.h>
void main()
{
int a=10,c=20;
long f;
c = sizeof(a+f);
printf(“%d”,c);
}

  1. 2
  2. 4
  3. Un defined size
  4. Depends on compiler

Answer :

Ans : 2 ; On any C compiler, the size of float is 4 bytes. Hence the size of expression is 4 bytes

What is the Output of following Code?
#include<stdio.h>
void main()
{
signed short s = 612 ;
printf(“%c”, s);
}

  1. Garbage character
  2. Compiler error
  3. 100
  4. d

Answer :

Ans : 4 ; When we count 612 value in character limits(256), the value is equals to 100 and the corresponding character is ‘d’

>C Technical Interview Questions – Datatypes Part 2<

Share this