Data type questions in c



Data types interview questions and answers with explanation


Note: Size of data types in C is compiler-dependent. The answers provided are based on compilers with a word size of two bytes. Please adjust the answers according to the size of data types in your compiler. In this context:

  • char: 1 byte
  • int: 2 bytes
  • float: 4 bytes
  • double: 8 bytes

This information is crucial for interpreting and adjusting the answers based on the specific characteristics of your compiler.



Frequently asked technical objective types multiple choice data types questions of placement in  c programming language

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

#include<stdio.h>
int main(){
    printf("%d\t",sizeof(6.5));
    printf("%d\t",sizeof(90000));
    printf("%d",sizeof('A'));
    return 0;
}

Choose all that apply:
(A)4 2 1
(B)8 2 1 
(C)4 4 1
(D)8 4 1
(E)8 4 2


Explanation:

Turbo C++ 3.0: 8 4 2
Turbo C ++4.5: 8 4 2
Linux GCC:  8 4 4
Visual C++: 8 4 4

The default data type assignments for numeric constants are as follows:

6.5: double
90000: long int
'A': char
It's important to note that in the C programming language, the size of data types can vary from one compiler to another. In the case of TURBO C 3.0, a 16-bit compiler, the sizes are as follows:

double: 8 bytes
long int: 4 bytes
Character constant: 2 bytes (though the size of the char data type is typically 1 byte)
For more modern compilers like TURBO C 4.5 or Linux GCC (32-bit compilers), the sizes differ:

double: 8 bytes
long int: 8 bytes
Character constant: 2 bytes




  

2.

Consider on following declaring of enum.
(i)        enum  cricket {Gambhir,Smith,Sehwag}c;
(ii)      enum  cricket {Gambhir,Smith,Sehwag};
(iii)    enum   {Gambhir,Smith=-5,Sehwag}c;
(iv)      enum  c {Gambhir,Smith,Sehwag};
Choose correct one:
(A)
Only (i) is correct declaration
(B)Only (i) and (ii) is correct declaration
(C)Only (i) and (iii) are correct declaration
(D)Only (i),(ii) and are correct declaration
(E)All four are correct declaration


Explanation:

Syntax of enum data type is:
enum  [<tag_name>]{
    <enum_constanat_name> [=<integer_ value>],
    …
} [<var_name>,…]

Note:
[] : Represents optional .
<>: Represents any valid c identifier

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

#include<stdio.h>
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;
}

Choose all that apply:
(A)0 0
(B)65536 -10 
(C)0 65536 
(D)65536 0
(E)Compilation error


Explanation:

Turbo C++ 3.0: 0 0
Turbo C ++4.5: 0 0
Linux GCC: 0 0
Visual C++: 0 0

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 casted 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

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

(A)extern
(B)interrupt
(C)huge
(D)register
(E)All of these are modifiers of data type


Explanation:

To know more about these go to following link:

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

#include<stdio.h>
int main(){
    double num=5.2;
    int  var=5;
    printf("%d\t",sizeof(!num));
    printf("%d\t",sizeof(var=15/2));
    printf("%d",var);
    return 0;
}

Choose all that apply:
(A)4 2 7
(B)4 4 5
(C)2 2 5
(D)2 4 7
(E)8 2 7


Explanation:

Turbo C++ 3.0: 2 2 5
Turbo C ++4.5: 2 2 5
Linux GCC: 4 4 5
Visual C++: 4 4 5

sizeof(Expr)  operator always returns the an integer value which represents the size of the final value of the expression expr.
Consider on the following expression:
!num
=!5.2
=0
0 is int type integer constant and it size is 2 by in TURBO C 3.0 compiler and  4 in the TURBO C 4.5 and Linux GCC compilers.
Consider on the following expression:
var = 15/2
=> var = 7
=> 7
7 is int type integer constant.
Any expression which is evaluated inside the sizeof operator its scope always will be within the sizeof operator. So value of variable var will remain 5 in the printf statement.

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

#include<stdio.h>
int main(){
    const int *p;
    int a=10;
    p=&a;
    printf("%d",*p);
    return 0;
}

Choose all that apply:
(A)0
(B)10
(C)Garbage value
(D)Any memory address
(E)Error: Cannot modify const object


Explanation:

Turbo C++ 3.0: 10
Turbo C ++4.5: 10
Linux GCC: 10
Visual C++: 10

In the following declaration
const int *p;
p can keep address of constant integer.

7.
Consider on following declaration:
(i)        short i=10;
(ii)      static i=10;
(iii)    unsigned i=10;
(iv)      const i=10;

Choose correct one:
(A)
Only (iv) is incorrect
(B)Only (ii) and (iv) are incorrect
(C)Only (ii),(iii) and (iv) are correct
(D)Only (iii) is correct
(E)All are correct declaration 


Explanation:

Default data type of above all declaration is int.

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

#include<stdio.h>
int main(){
    int a= sizeof(signed) +sizeof(unsigned);
    int b=sizeof(const)+sizeof(volatile);
    printf("%d",a+++b);
    return 0;
}

Choose all that apply:
(A)10
(B)9
(C)8
(D)Error: Cannot find size of modifiers
(E)Error: Undefined operator +++


Explanation:

Turbo C++ 3.0: 8
Turbo C ++4.5: 8
Linux GCC: 16
Visual C++: 16

Default data type of signed, unsigned, const and volatile is int. In turbo c 3.0 size of int is two byte.
So, a = 4 and b =4
Now, a+++b
= a++ + b
= 4 + 4  //due to post increment operator.
=8
Note: In turbo c 4.5 and Linux gcc compiler size of int is 4 byte so your out will be 16

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

#include<stdio.h>
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;
}

Choose all that apply:
(A)10 -10   0 0
(B)10 -10   65516 -10 
(C)10 -10   10 -10
(D)10 65526      0 0
(E)Compilation error


Explanation:

Turbo C++ 3.0: 10 65526 0 0
Turbo C ++4.5: 10 65526 0 0
Linux GCC: 10 4294967286 0 0 
Visual C++: 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

10.
Which of the following is integral data type?

(A)void
(B)char
(C)float
(D)double
(E)None of these


Explanation:

In C, the char data type is considered integral, capable of storing the ASCII value of any character constant.

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

#include<stdio.h>
int main(){
    volatile int a=11;
    printf("%d",a);
    return 0;
}

Choose all that apply:
(A)11
(B)Garbage
(C)-2
(D)We cannot predict
(E)Compilation error


Explanation:

Turbo C++ 3.0: We cannot predict
Turbo C ++4.5: We cannot predict
Linux GCC: We cannot predict
Visual C++: We cannot predict

The value of a volatile variable cannot be reliably predicted, as it can be altered by any microprocessor interrupt.
12.
What is the range of signed int data type in that compiler in which size of int is two byte?
(A)-255 to 255
(B)-32767 to 32767
(C)-32768 to 32768
(D)-32767 to 32768
(E)-32768 to 32767


Explanation:

Note: The size of the int data type is consistently equal to the word length of the microprocessor on which your compiler is based.






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

#include<stdio.h>
const enum Alpha{
      X,
      Y=5,
      Z
}p=10;
int main(){
    enum Alpha a,b;
    a= X;
    b= Z;
    printf("%d",a+b-p); 
    return 0; 
}

Choose all that apply:
(A)-4
(B)-5 
(C)10
(D)11
(E)Error: Cannot modify constant object


Explanation:

Turbo C++ 3.0: -4
Turbo C ++4.5: -4
Linux GCC: -4
Visual C++: -4

Default value of enum constant X is zero and
Z = Y + 1 = 5 + 1 = 6
So, a + b – p
=0 + 6 -10 = -4

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

#include<stdio.h>
int main(){
    char a=250;
    int expr;
    expr= a+ !a + ~a + ++a;
    printf("%d",expr);
    return 0;
}

Choose all that apply:
(A)249
(B)250
(C)0
(D)-6
(E)Compilation error


Explanation:

Turbo C++ 3.0: -6
Turbo C ++4.5: -6
Linux GCC: -6
Visual C++: -6

char a = 250;
250 is beyond the range of signed char. Its corresponding cyclic value is: -6
So, a = -6
Consider on the expression:
expr= a+ !a + ~a + ++a;
Operator! , ~ and ++ have equal precedence. And it associative is right to left.
So, First ++ operator will perform the operation. So value a will -5
Now,
Expr = -5 + !-5 + ~-5 + -5
= -5 + !-5 + 4 - 5
= -5 + 0 + 4 -5
= -6

15.
Consider on order of modifiers in following declaration:

(i)char volatile register unsigned c;
(ii)volatile register unsigned char c;
(iii)register volatile unsigned char c;
(iv)unsigned char volatile register c;










(A)Only (ii) is correct declaration
(B)Only (i) is correction declaration
(C)All are incorrect
(D)All are correct but they are different
(E)All are correct and same


Explanation:

The order of modifiers for a variable in C does not have any significance.

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

#include<stdio.h>
int main(){
    int a=-5;
    unsigned int b=-5u;
    if(a==b)
         printf("Avatar");
    else
         printf("Alien");
    return 0;
}

Choose all that apply:
(A)Avatar
(B)Alien
(C)Run time error
(D)Error: Illegal assignment
(E)

Error: Don’t compare signed no. with unsigned no.



Explanation:

Turbo C++ 3.0: Avatar
Turbo C ++4.5: Avatar
Linux GCC: Avatar
Visual C++: Avatar

int a=-5;
Here variable a is by default signed int.
unsigned int b=-5u;
Constant -5u will convert into unsigned int. Its corresponding unsigned int value will be :
65536 – 5 + 1= 65532
So, b = 65532

In any binary operation involving dissimilar data types, such as a == b, the lower data type operand is automatically type-casted into the operand of the higher data type before the operation is performed, and the result will be of the higher data type.

In C, a signed int is considered a higher data type than an unsigned int. Therefore, variable b will be automatically type-casted into a signed int. Consequently, the corresponding signed value of 65532 is -5.

Hence, the expression a == b holds true.






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

#include<stdio.h>
extern enum cricket x;
int main(){
    printf("%d",x); 
    return 0;
}
const enum cricket{
    Taylor,
    Kallis=17,
    Chanderpaul
}x=Taylor|Kallis&Chanderpaul;

Choose all that apply:
(A)0
(B)15
(C)16
(D)17
(E)Compilation error


Explanation:

Turbo C++ 3.0: 16
Turbo C ++4.5: Compilation error
Linux GCC: Compilation error
Visual C++: 16

x=Taylor|Kallis&Chanderpaul
= 0 | 17 & 18
= 0 |(17 & 18)
//& operator enjoy higher precedence than |
=0 |16
=16

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

(A)Function
(B)Pointer
(C)Enumeration
(D)Array
(E)All are derived data type


Explanation:

Enum is primitive data type.

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

#include<stdio.h>
enum A{
    x,y=5,
    enum B{
         p=10,q
    }varp;
}varx;

int main(){
    printf("%d %d",x,varp.q);
    return 0;
}

Choose all that apply:
(A)0 11
(B)5 10 
(C)4 11
(D)0 10
(E)Compilation error


Explanation:

Turbo C++ 3.0: Compilation error
Turbo C ++4.5: Compilation error
Linux GCC: Compilation error
Visual C++: Compilation error

Nesting of enum constant is not possible in c.

20.
Consider on following declaration in c:

(i)short const register i=10;
(ii)static volatile const int i=10;
(iii)unsigned auto long register i=10;
(iv)signed extern float i=10.0;

Choose correct one:
(A)Only (iv)is correct
(B)Only (ii) and (iv) is correct
(C)Only (i) and (ii) is correct
(D)Only (iii) correct
(E)All are correct declaration 


Explanation:

  • If option (III) suggests specifying both auto and register in the declaration of a variable, then you are correct. In C, a variable cannot have both auto and register storage class specifiers.


  • If option (IV) suggests using signed or unsigned modifiers with float data type, then you are also correct. In C, the float data type is by default considered signed, and using signed or unsigned with float is not allowed.

If you have a specific question or context related to these options, feel free to provide more details, and I'll do my best to assist you.



76 comments:

Anonymous said...

nice

Anonymous said...

thanks itz really good

Anonymous said...

Really thanks 4 providing such a huge range of beyond imagination quests.. Thanks a lot...
@Admin: jz an advice for options of answers use radiobutton group instead.. because multiple answers are getting selected of same quest and they arent getting unchecked also..

sateeshnaidu said...

for question 1 output is 8 4 1.

sateeshnaidu said...

can u provide solution to que:4

Anonymous said...

How i present 0123 as integer variable.

Unknown said...

Marvelous...Very useful to me....My grateful thanks to you......................

Anonymous said...

hey where can i find a pdf of all these questions ?

Unknown said...

its very useful to me,,,,,,,,,,,,,,,,thanks

Anonymous said...

Plz Clear Question No.14 because what is -6. signed char range is 0 to -128 to 127

Anonymous said...

hey anonymous i googled n got the answer for ur above question.. here it is....

Cyclic nature of data type in C
In C some data types shows one special properties that when we assign a value beyond range of that data type then it will not any compiler error but assign a number according to some cyclic order. This property is known as cyclic nature of data type.
Data type which shows cyclic nature:
(a) char
(b) int
(c) long int
Data type which doesn’t show cyclic nature:
(a) float
(b) double
(c) long double

1. Cyclic nature of unsigned char:
Range of unsigned char is 0 to 255. If we will assign a value greater than 255 then value of variable will be changed to a value if we will move clockwise direction as shown in the figure according to number. If number is less than 0 then move in anti clockwise direction.


Short cut formula to find cyclic value:
If number is X where X is greater than 255 then
New value = X % 256
If number is Y where Y is less than 0 then
New value = 256 – (Y% 256)


2. Cyclic nature of signed char:

Range of unsigned char is -128 to 127. If we will assign a value greater than 127 then value of variable will be changed to a value if we will move clockwise direction as shown in the figure according to number. If number is less than -128 then move in anti clockwise direction.



Short cut formula to find cyclic value:
If number is X where X is greater than 127 then
p = X % 256
if p <=127
New value = p
else
New value = p – 256
If number is Y where Y is less than -128 then
p = Y % 256
If p <= 127
New value = -p
else
New value = 256 -p

My name Ayesha

Priyanka kumari said...

I hope this link will help you.

Cyclic nature of data types

Unknown said...

very nice
you can test your c skills

Anonymous said...

where did you get int's size is 2, it is 4 byte.

Shree said...

very nice
this test is amesign cncept

sunil mundhara said...

nice exercises!! learned a lot of new things!!

Anonymous said...

nice really.. njoy it...

Anonymous said...

Can anyone explain the output of program as under:

#include
int array[]={1,2,3,4,5,6,7,8};
#define SIZE (sizeof(array)/sizeof(int))
main()
{
if(-1<=SIZE) printf("1");
else printf("2");
}

Unknown said...

what is the output of this program....and also explain it..how the answer it comes
main()
{
int a, b, c;
a = 10;
b = 20;
c = printf("%d",a) + ++b;
printf ("%d",c);
}

Anonymous said...

i think the output will be 31..because here we used pre increment operation for b
i.e.,10+21=31.


or else the output will be 1023

Anonymous said...

2

Unknown said...

#include
#include
void main()
{
float a=0.7;
if(a<0.7)
printf("stoned");
else
printf("Avenged");
}

Unknown said...

plz reply what is the ans

vijay said...

here the reason is real numbers are stored in IEEE 754 format so the bit fields for float fills out to be 32 bit ie..a
where as the bit fields for 0.7 which by default acts as double which is of 64 bits when you try to compare a will be lesser than 0.7 because the a is type casted implicitly which implicitly becomes 8 bytes .for further details look at memory representation of real numbers.

Anonymous said...

2+21=23

because printf("%d",a) results 2 because a= 10 has two digits ..

Unknown said...

Explain how its output is 1023

triggers said...

bro how you created this quizz and can you tell me which site u used to create this quiz :)

Himanshu said...

good knowledge of quiz thanks..

Unknown said...

the solution is 8 4 2

Anonymous said...

please explane me this the output is 1 7
#include

int x = 0;

int main()

{

int i = (f() + g()) | g(); //bitwise or

int j = g() | (f() + g()); //bitwise or
printf("%d",i);
printf("%d",j);
}

int f()

{

if (x == 0)

return x + 1;

else

return x - 1;

}

int g()

{

return x++;

}

Anonymous said...

why is 8 4 2? more precisely why is ..2 instead 1(char : 1 byte)

Unknown said...

why because char constant consider a int so what it showing 4 bytes for example the capital value of A equivalent int value is 65(int) if u going to print both is same
printf(sizeof('A'));

printf(sizeof(65));

Anonymous said...

very useful for all beginers

Unknown said...

in tubo c int's size is 2

sushant kumar said...

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

#include
int main(){
volatile int a=11;
printf("%d",a);
return 0;
}

i have executed this code on GCC compiler and i am getting the output as 11.
but in the explanation of this code it is written that compiler can not predict the volatile variable.. why it is so ... please clear my doubt.

CHANDA N said...

What are the various stage of programming development ?

CHANDA N said...

Explain different tools for program logic development.

CHANDA N said...

Why are flow-charts used? Explain symbols for making a flow chart-charts?

CHANDA N said...

What are main programming characteristics?

CHANDA N said...

What are various methods of compiling a C program?

CHANDA N said...

Write a C program to find the largest of three numbers.

CHANDA N said...

Write a note on operator in C.

CHANDA N said...

what are statement different types in C? Explain all three iterative statement with syntax.

CHANDA N said...

define array. How will you do the following?:
1. declare array
2. Initialize array
3. Enter data in array
4. Access elements of an array
5. Get output from an array.
--- - -- - and - --- - -
Write a program to add two 3*3 matrix using array.

CHANDA N said...

best question of c language:-
Question:- Define function. What are advantage of using functions? how are functions.

Unknown said...

8 4 2 is the output

Engg Warez said...

main can be written as var name

Unknown said...

thanks for this question

vinay said...

in qstn no 13 how we get z=y+1 ??

Anonymous said...

write a program that input two number and finds if second number is square of 1st number

Anonymous said...

please solve this program plz

Anonymous said...

write a program that input two number and finds if second number is square of 1st number
please solve this program plz

Unknown said...

awesome

Unknown said...

Great post

Vrushali said...

Gud post,please add data structure mcq type questions n answer.

traininginstitute said...


Really nice and interesting post. I was looking for this kind of information and enjoyed reading this one. Keep posting. Thanks for sharing.
digital marketing courses in hyderabad with placement



traininginstitute said...

I think I have never seen such blogs before that have completed things with all the details which I want. So kindly update this ever for us.

digital marketing courses in hyderabad with placement

traininginstitute said...

Excellent effort to make this blog more wonderful and attractive.
digital marketing courses in hyderabad with placement

Ramesh Sampangi said...

Thanks for sharing this article. Keep sharing some more blogs again soon.
ai training in hyderabad

Ramesh Sampangi said...

Thanks for sharing this blog with us. I hope the below link is useful for data science enthusiasts.
Best Data Science Training Hyderabad

Priya Rathod said...

Thank you for sharing such a wonderful article! It provides excellent and helpful pieces of information. It's great that you are taking the time to share your expertise with others. Please continue writing articles that can be useful to readers like myself who may not be aware of some of these tips and tricks!
Data Science Training in Hyderabad
Data Science Course in Hyderabad

jony blaze said...

I like the helpful content and as always keep us updated and posted. Share your info with us please.
Data Science Training in Hyderabad
Data Science Course in Hyderabad

Priya Rathod said...

Your blog has so many great articles. I was impressed by the great job you have done with the way each topic is presented in your writing.
AWS Training in Hyderabad
AWS Course in Hyderabad

Arnold DK said...

Nice post. it is very good question of data topic. I'm impressed! Extremely useful information. Thank you and keep up the good work. whatsapp mod

Thomya_Patlacha. said...

Thank You for this interview questions. I will remember this. Hope you will support same in future..




GBWhatsapp APK 2022




isabella said...

I just want to let you know that I am a beginner to blog and of course I have enjoyed your web page. What is an Indian Business Visa? Indian Business Visa is an electronic business travel authorization. Apply for Indian business e-visa online through the Indian Visa website, and the cost for the Indian business e-Visa depending on the traveler's nationality and the urgency of the visa required by the traveller.

Zanaib said...

A degree in cybersecurity will most certainly require that additional courses be taken. Additionally, thought will need to be given with respect to the funds required for those additional courses and the resulting degree. UMBC Cybersecurity Courses List

Namita Aggarwal said...

Looking for a hotel in Mathura Vrindavan? We offer affordable accommodations and a variety of amenities to make your stay with us comfortable and enjoyable. Book your room today! Mathura Vrindavan Hotel Booking

Venkat Kaur said...

Asset Plus Buyers Agents is the perfect choice if you're looking for the best buyers agent near me. We're a team of experienced professionals dedicated to helping you find the ideal property. We'll work with you to find the right property, negotiate the best price, and help you through the entire process. Contact us today, and let us help you find your dream property. Buyers agent near me

Molly Greville said...

Are you looking for the best Online Piano Lessons Near Me in sydney, Australia? Our highly experienced and certified instructors offer lessons for all levels, from beginner to advanced. We also offer a wide range of styles, from classical to pop to jazz.

Radhika Sharma said...

Are you looking for the Best Luxury Home Builders in Melbourne, Australia? Bullseye Home Builders are the experts in high-end home construction, focusing on quality craftsmanship and innovative design. We build homes that are not only beautiful and luxurious but also functional and liveable.

Venkat Kaur said...

Are you looking for a professional Wallpaper Installation in Melbourne, Australia? Divine Interiors offers a wide range of wallpaper installation services to suit your needs. We have a team of experienced and qualified wallpaper installers who can do the job quickly and efficiently. Contact us today for a free quote.

Ajay said...

Are you looking for an Online Hacking Course in Hindi? Cyberpratibha offers a comprehensive course that will teach you everything you need to know about hacking. With over 50 hours of content, you will learn the basics of hacking, how to protect yourself from hackers, and how to use hacking to your advantage.

Anonymous said...

Fantastic article with valuable information found it very useful looking forward to the next blog thank you.

https://espirittech.com/delphi-development/

Anonymous said...

This is a great post I saw, thanks for sharing. I really want to hope that you will continue to share great posts in the future.

Delphi Development Services
Delphi Development Company

Kairon said...

¡Gran post sobre tipos de datos en C! Como desarrollador, también trabajo con APK Mod App en Android y veo muchas similitudes en la gestión de memoria. ¡Sigue así!