Data Types in C Language - General Knowledge Question and Answer

Data Types in C Language - Question and Answer

Which of the following is not a valid declaration in C?

1. short int x;

2. signed short x;

3. short x;

4. unsigned short x;

 


1
2
3 and 4
All

Answer:

All are valid


Share Me:

What is the Output of this program?
#include <stdio.h>
int main()
{
   float c = 5.0;
   printf ("Temperature in Fahrenheit is %.2f", (9/5)*c + 32);
   return 0;
}
 


Temperature in Fahrenheit is 31.00
Temperature in Fahrenheit is 46.00
Temperature in Fahrenheit is 40.00
Temperature in Fahrenheit is 37.00

Answer:

Temperature in Fahrenheit is 37.00


Share Me:

What is the output of this code?
#include <stdio.h>
int main()
 {
  int a[5] = {1, 2, 3, 4, 5};
  int i;
    for (i = 0; i < 5; i++)
          if ((char)a[i] == '5')
             printf("%d\n", a[i]);
          else
             printf("ATNYLA\n");
 }
 


Program will compile and print the output ATNYLA
Program will compile and print ATNYLA for 5 times
Program will compile and print the ASCII value of ATNYLA
The compiler will flag an error

Answer:

Output:

ATNYLA
ATNYLA
ATNYLA
ATNYLA
ATNYLA

Share Me:

Which of the datatypes have size that is variable?  


Array
Structure
Union
All

Answer:

Since the size of the structure depends on its fields, it has a variable size.


Share Me:

Which data type is most suitable for storing a number 65000 in a 32-bit system?  


Unsigned short
Long
Int
Signed short

Answer:

65000 comes in the range of short (16-bit) which occupies the least memory. Signed short ranges from -32768 to 32767 and hence we should use unsigned short.


Share Me:

What is the size of an int data type in a 32-bit system?  


4 Bytes
8 Bytes
2 Bytes
Depends on the system/compiler

Answer:

The size of an int data type in a 32-bit system is 2 Bytes


Share Me:

What is the output of this C code?
#include <stdio.h>
int main()
 {
  signed char chr;
  chr = 200;
  printf("%d\n", chr);
  return 0;
 }
 


-56
200
-200
Depends on the computer

Answer:

Output:

-56

Share Me:

What is the output of this C Program?
#include <stdio.h>
int main()
 {
  float f1 = 0.1;
  if (f1 == 0.1)
    printf("equal\n");
  else
    printf("not equal\n");
 }
 


not equal
equal
Output depends on compiler
None of the mentioned

Answer:

Output

not equal

0.1 by default is of type double which has different representation than float resulting in inequality even after conversion.


Share Me:

What is the output of this C code?
#include <stdio.h>
int main()
 {
  float f1 = 0.1;
  if (f1 == 0.1f)
  printf("equal\n");
  else
  printf("not equal\n");
 }
 


not equal
equal
Output depends on compiler
None of the mentioned

Answer:

Output

equal

0.1f results in 0.1 to be stored in floating point representations.


Share Me:

Which is correct with respect to the size of the datatypes?  


char > int > float
int > char > float
char < int < double
double > char > int

Answer:

char has lesser bytes than int and int has lesser bytes than double in any system


Share Me:

What is the output of the following C code on a 64 bit machine?
#include <stdio.h>
union Sti
 {
  int nu;
  char m;
 };
  int main()
   {
    union Sti s;
    printf("%d", sizeof(s));
    return 0;
   }
 


5
4
8
9

Answer:

Output:

4

Since the size of a union is the size of its maximum datatype, here int is the largest hence 4.


Share Me:

What is the output of the following C code?
#include <stdio.h>
int main()
 {
   float x = 'b';
   printf("%f", x);
   return 0;
 }
 


b
b.0000000
run time error
98.000000

Answer:

Output:

98.000000

Since the ASCII value of b is 98, the same is assigned to the float variable and printed.


Share Me:

What will be output when you will execute following c code on a 64-bit machine?
#include
int main(){
    int a= sizeof(signed) +sizeof(unsigned);
   printf("%d",a);
    return 0;
}
 


10
9
8
Cannot find size of modifiers

Answer:

Output:

8

Default data type of signed, unsigned is int. In 64-bit machine size of int is 4 byte.

signed=4

unsigned=4

Then, 4+4=8


Share Me:

What will be output when you will execute following c code on a 32-bit machine?
#include
int main(){
    int b=sizeof(const)+sizeof(volatile);
    printf("%d",b);
    return 0;
}
 


8
4
16
32

Answer:

Output:

4

Default data type of signed, unsigned is int. In 32-bit machine size of int is 2 byte.

signed=2

unsigned=2

Then, 2+2=4


Share Me:

Which of the following is not modifier of data type in c?  


extern
interrupt
huge
All

Answer:

All are not modifier. Also register is not a modifier.


Share Me:

What will be output when you will execute following c code?
#include
int main(){
    printf("%d\t",sizeof(6.5));
    printf("%d\t",sizeof(90000));
    printf("%d",sizeof('A'));
    return 0;
}
 


4 4 1
16 8 4
8 4 2
4 2 1

Answer:

Output on Turbo C++ 3.0:

8 4 2

Output on Turbo C++ 4.5:

8 4 2

Output on Linux GCC:

8 4 4

Output on Visual C++:

8 4 4

By default data type of numeric constants is:

6.5 : double

90000: long int

'A': char

In C size of data type varies from compiler to compiler.


Share Me:

What will be output when you will execute following c code?

 #include
  int main(){
    signed x;
    unsigned y;
    x = 10 +- 10u + 10u +- 10;
    y = x;
    if(x==y)
         printf("%d %d",x,y);
    else if(x!=y)
         printf("%u  %u",x,y);
    return 0;
}
 


65536 -10
0 65536
0 0
Compilation error

Answer:

Consider on the expression:

x = 10 +- 10u + 10u +- 10;

10: It is signed integer constant.

10u: It is unsigned integer constant.

X: It is signed integer variable.

In any binary operation of dissimilar data type for example: a + b

Lower data type operand always automatically type cast into the operand of higher data type before performing the operation and result will be higher data type.

As we know operators enjoy higher precedence than binary operators. So our expression is:

x = 10 + (-10u) + 10u + (-10);

= 10 + -10 + 10 + (-10);

= 0

Note: Signed is higher data type than unsigned int.

So, Corresponding signed value of unsigned 10u is +10


Share Me:

What will be output when you will execute following c code?

#include
   int main(){
    signed x,a;
    unsigned y,b;
    a=(signed)10u;
    b=(unsigned)-10;
    y = (signed)10u + (unsigned)-10;
    x = y;
    printf("%d  %u\t",a,b);
    if(x==y)
         printf("%d %d",x,y);
    else if(x!=y)
         printf("%u  %u",x,y);
    return 0;
}
 


10 4294967286 0 0
10 65526 0 0
A and B
None

Answer:

Output of Turbo C++ 3.0: 10 65526 0 0

10 65526 0 0

Turbo C ++4.5: 10 65526 0 0

10 65526 0 0

Linux GCC: 10 4294967286 0 0

10 4294967286 0 0

Visual C++: 10 4294967286 0 0

10 4294967286 0 0

a=(signed)10u;

signed value of 10u is +10

so, a=10

b=(unsigned)-10;

unsigned value of -10 is :

MAX_VALUE_OF_UNSIGNED_INT – 10 + 1

In turbo c 3.0 complier max value of unsigned int is 65535

So, b = 65526

y = (signed)10u + (unsigned)-10;

= 10 + 65526 = 65536 = 0 (Since 65536 is beyond the range of unsigned int. zero is its corresponding cyclic vlaue)

X = y = 0


Share Me:

Suppose a C program has floating constant 2.76, what's the best way to convert this as "float" data type?  


(float)2.76
2.76f or 2.76F
2.76 itself of "float" data type i.e. nothing else required.
float(2.76)

Answer:

By default floating constant is of a double data type. By suffixing it with f or F, it can be converted to float data type. For more details, this post can be referred here.


Share Me:

Which of the following is the correct default value of a Boolean type?  


0
1
True
False

Answer:

False is the correct default value of a Boolean type.


Share Me:

Which of the following is the correct way to set a value 3.14 in a variable pi such that it cannot be modified?  


pi = 3.14F;
const float pi = 3.14F;
const pi; pi = 3.14F;
float pi = 3.14F;

Answer:

pi = 3.14F; It doesn't declare the data type.

const float pi = 3.14F; is the correct Answer. It declare constant datatype.

const pi; pi = 3.14F; Here data type doesn't declare.

float pi = 3.14F; pi is a floating-point variable but not a constant.


Share Me:

What will be output when you will execute following c code?
#include
int main(){
    volatile int x=34;
    printf("%d",x);
    return 0;
}
 


34
Garbage
Compilation error
We cannot predict

Answer:

We cannot predict the value of volatile variable because its value can be changed by any microprocessor interrupt.


Share Me:

Which of the following does not store a sign?  


Short
Integer
Long
Byte

Answer:

Byte is the following does not store a sign.


Share Me:

What is the output of this program?
#include 
int main()
{
    if (sizeof(int) > -1)
        printf("Yes");
    else
        printf("No");
    return 0;
}
   


No
Yes
Compile time error
Run time Error

Answer:

In C, when an integer value is compared with an unsigned it, the int is promoted to unsigned. Negative numbers are stored in 2's complement form and unsigned value of the 2's complement form is much higher than the sizeof int.


Share Me:

What is the size of a Decimal number in 64-bit?  


4 byte
8 byte
16 byte
32 byte

Answer:

16 byte is the size of a Decimal number in 64-bit


Share Me:

Which of the following is NOT an Integer?  


Byte
Char
Integer
Short

Answer:

Char is NOT an Integer.


Share Me:

Which of the following is not derived data type in c?  


Pointer
Enumeration
Function
Array

Answer:

Enumeration is not derived data type in c. It is primitive data type.


Share Me:

Which one is a modifier in data type?  


sign
unsign
long
All

Answer:

All are modifier in data type.


Share Me:

What is short int in C programming?  


short is the qualifier and int is the basic datatype
All are Qualifier
Basic data type of C
All of the mentioned.

Answer:

short is the qualifier and int is the basic datatype


Share Me:

What is the output of this C code?
#include<stdio.h> 
void main()
 {
  1 < 2 ? return 1: return 2;
 }
 


Run time error
Varies
-5
5

Answer:

-5

Share Me:

What is the output of this C code?
#include<stdio.h> 
void main()
{
   char a='\012';
   printf("%d",a);
 
}
 


10
11
12
012

Answer:

Option A

Share Me:

Among the following which one is not a valid identifier?  


Y12
Sum_1
_temperature
4th

Answer:

4th

Share Me:

What would be the output of the following program?
#include 
 int x = 40 ;
void main()
{

    int x = 20 ;
    printf("\n%d ",x);
}

 


21
20
22
no output

Answer:

Run in 6b-bit machine
20 Press any key to continue . . .

Share Me:

What would be the output of the following program?
#include 

void main()
{
    int x = 40 ;
    {
    int x = 20 ;
    printf("\n%d ",x);
    }
    printf("%d ",x);
}

 


40 20
21 40
20 40
20 41

Answer:

Run in 64-bit machine
20 40 Press any key to continue . . .

Share Me: