C Technical Interview Questions – Datatypes

These C Technical Interview Questions Datatypes post providing basic, intermediate and Hard level examples in C data types. The practice of these examples makes you good in C programming.


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

  1. Compiler error
  2. 45
  3. 0
  4. None of the above

Answer :

Ans : 3 ; Instead of omit the fractional part, it will print the value of 0 , because it cannot convert implicitly

What is the Output of following Code?
#include<stdio.h>
void main()
{
double PI = 3.142 + 0.0001111;
printf(“%f “, PI);
}

  1. 3.142111
  2. 3.1421111
  3. Compiler Error
  4. Garbage value

Answer :

Ans : 1 ; float value prints only upto 6 decimal values from the complete double value

What is the Output of following Code?
#include <stdio.h>
int main(void)
{
int f = 4;
printf(“%d %d\n”,f);
return 0;
}

  1. 4 , garbage value
  2. Compiler error
  3. garbage value, 4
  4. 4, 0

Answer :

Ans : 1 ; In C program, garbage values will be printed in place of specifiers with no variables

What is the Output of following Code?
int main(void)
{
int i = 20;
int j = 20;
int k = 20;
printf(“%d%o%x”, i, j,k );
return 0;
}

  1. 20,20,20
  2. 20,24,14
  3. 20, garbage value, garbage value
  4. Compile time error

Answer :

Ans : 2 ; It displays decimal number, octal number and hexa decimal number of value 20

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

  1. 34
  2. 0
  3. Garbage value
  4. Compile time error

Answer :

Ans : 1 ; When we type cast float value into integer, it omits only fractional part of that float value

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

  1. 256
  2. 0
  3. NULL character
  4. Compile time error

Answer :

Ans : 2 ; Float value stores into short variable as 256 and 256 corresponding character value is 0

What is the Output of following Code?
#include<stdio.h>
void main()
{
printf(“%d,”, sizeof(long int));
printf(“%d”, sizeof(long double));
}

  1. 4, 10
  2. 8 , 8
  3. 4, 8
  4. 8 ,10

Answer :

Ans : 1 ; In C, size of long int is 4 bytes and size of long double is 10 bytes

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

  1. 0 bytes
  2. 1 byte
  3. Compile time error
  4. 2 bytes

Answer :

Ans : 3 ; void data type doesn’t have size, it is a keyword

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

  1. Error : Undefined symbol
  2. -1
  3. 65535
  4. 0

Answer :

Ans : 2 ; USHRT_MAX is the pre-defined variable with value 65535 and it prints -1 as we used signed short int format specifier

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

  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>
#include<limits.h>
void main()
{
printf(“%d”, CHAR_BIT);
}

  1. 1
  2. 8
  3. 0
  4. Error : No such variable in C

Answer :

Ans : 2 ; limits.h header file contains this pre-defined variable that represents size of character in bits

> C Technical Interview Questions on Datatypes – Objective Type <

Share this