wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

C Programming : Data types and Operators

Total questions: 39

Worksheet time: 20mins

Name
Class
Date
1.

What is short int in C programming?

a)

Qualifier

b)

Short is the qualifier and int is the basic data type

c)

All of the mentioned

d)

The basic data type of C

2.

What will be the output of the following C code? #include int main() { signed char chr; chr = 128; printf("%d\n", chr); return 0; }

a)

None of the mentioned

b)

-128

c)

128

d)

Depends on the compiler

3.

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

a)

signed short

b)

int

c)

unsigned short

d)

long

4.

What will be the output of the following C code? #include 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("FAIL\n"); }

a)

The compiler will flag an error

b)

The program will compile and print the ASCII value of 5

c)

The program will compile and print FAIL for 5 times

d)

The program will compile and print the output 5

5.

What is the size of an int data type?

a)

Cannot be determined

b)

Depends on the system/compiler

c)

4 Bytes

d)

8 Bytes

6.

The format identifier '%i' is also used for _____ data type.

a)

char

b)

int

c)

double

d)

float

7.

Which is correct with respect to the size of the data types?

a)

char > int > float

b)

double > char > int

c)

int > char > float

d)

char < int < double

8.

Which of the data types has the size that is variable?

a)

double

b)

struct

c)

int

d)

float

9.

What will be the output of the following C code? #include int main() { float f1 = 0.1; if (f1 == 0.1) printf("equal\n"); else printf("not equal\n"); }

a)

equal

b)

output depends on the compiler

c)

not equal

d)

error

10.

What will be the output of the following C code? #include int main() { float x = 'a'; printf("%f", x); return 0; }

a)

a

b)

a.0000000

c)

97.000000

d)

run time error

11.

What will be the output of the following C code on a 32-bit machine? #include <stdio.h> int main() { int x = 10000; double y = 56; int *p = &x; double *q = &y; printf("p and q are %d and %d", sizeof(p), sizeof(q)); return 0; }

a)

compiler error

b)

p and q are 4 and 4

c)

p and q are 2 and 8

d)

p and q are 4 and 8

12.

Predict the output of following program. Assume that the numbers are stored in 2's complement form. #include int main() { unsigned int x = -1; int y = ~0; if (x == y) printf("same"); else printf("not same"); return 0; }

a)

same

b)

not same

13.

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

  1. 1. short int x;

 2. signed short x;

  1. 3. short x;

  1. 4. unsigned short x;

a)

3 and 4

b)

2

c)

1

d)

All are valid

14.

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

a)

Temperature in Fahrenheit is 41.00

b)

Temperature in Fahrenheit is 37.00

c)

Temperature in Fahrenheit is 0.00

d)

C

15.

Predict the output of following C program #include <stdio.h> int main() { char a = 012; printf("%d", a); return 0; }

a)

Compiler Error

b)

12

c)

10

d)

Empty

16.

In C, sizes of an integer and a pointer must be same.

a)

True

b)

False

17.

Predict the output of following C program #include<stdio.h> int main() { void *vptr, v; v = 0; vptr = &v; printf("%v", *vptr); getchar(); return 0; }

a)

0

b)

Compiler Error

c)

Garbage Value

18.

Predict the output of following C program #include<stdio.h> int main() { char c = 125; c = c+10; printf("%d", c); return 0; }

a)

135

b)

+INF

c)

-121

d)

-8

19.

Predict the output of following C program #include <stdio.h> int main() { if (sizeof(int) > -1) printf("Yes"); else printf("No"); return 0; }

a)

Yes

b)

No

c)

Compiler Error

d)

Runtime Error

20.

In a C program, following variables are defined: float x = 2.17; double y = 2.17; long double z = 2.17; Which of the following is correct way for printing these variables via printf.

a)

printf("%f %lf %Lf",x,y,z);

b)

printf("%f %f %f",x,y,z);

c)

printf("%f %ff %fff",x,y,z);

d)

printf("%f %lf %llf",x,y,z);

21.

"typedef" in C basically works as an alias. Which of the following is correct for "typedef"?

a)

typedef can be used to alias compound data types such as struct and union.

b)

typedef can be used to alias pointer to compound types

c)

typedef can be used to alias a function pointer.

d)

All of the above.

22.

In a C program snippet, followings are used for definition of Integer variables signed s; unsigned u; long l; long long ll; Pick the best statement for these.

a)

All of the above variable definitions are incorrect because basic data type int is missing.

b)

All of the above variable definitions are correct because int is implicitly assumed in all of these.

c)

Only "long l;" and "long long ll;" are valid definitions of variables.

d)

Only "unsigned u;" is valid definition of variable.

23.

What will be the output of the following C code? #include<stdio.h> #include<string.h> int main() { char *str = "x"; char c = 'x'; char ary[1]; ary[0] = c; printf("%d %d", strlen(str), strlen(ary)); return 0; }

a)

1 0

b)

2 1

c)

1 1

d)

2 2

24.

What will be the output of the following C code?

 #include <stdio.h>

    int main()

    {

        enum {ORANGE = 5, MANGO, BANANA = 4, PEACH};

        printf("PEACH = %d\n", PEACH);

    }

a)

PEACH = 6

b)

PEACH = 3

c)

PEACH = 4

d)

PEACH = 5

25.

What will be the output of the following C code?

    #include <stdio.h>

    #define a 10

    int main()

    {

        const int a = 5;

        printf("a = %d\n", a);

    }

a)

a = 5

b)

Compilation error

c)

Runtime error

d)

a = 10

26.

What will be the output of the following C function?

 #include <stdio.h>

    enum birds {SPARROW, PEACOCK, PARROT};

    enum animals {TIGER = 8, LION, RABBIT, ZEBRA};

    int main()

    {

        enum birds m = TIGER;

        int k;

        k = m;

        printf("%d\n", k);

        return 0;

    }

a)

1

b)

Compile time error

c)

0

d)

8

27.

What will be the output of the following C code?

 #include <stdio.h>

    int main()

    {

        int i = -3;

        int k = i % 2;

        printf("%d\n", k);

    }

a)

Implementation defined

b)

Compile time error

c)

-1

d)

1

28.

What will be the output of the following C code?

  #include <stdio.h>

    void main()

    {

        int y = 3;

        int x = 5 % 2 * 3 / 2;

        printf("Value of x is %d", x);

    }

a)

Value of x is 3

b)

Compile time error

c)

Value of x is 1

d)

Value of x is 2

29.

What will be the output of the following C code?

    #include <stdio.h>

    int main()

    {

        int i = 3;

        int l = i / -2;

        int k = i % -2;

        printf("%d %d\n", l, k);

        return 0;

    }  

a)

Implementation defined

b)

Compile time error

c)

-1 1

d)

1 -1

30.

What will be the output of the following C code? #include <stdio.h> int main() { int x = 1, y = 0, z = 3; x > y ? printf("%d", z) : return z; }

a)

Compile time error

b)

3

c)

Run time error

d)

1

31.

What will be the output of the following C code? #include <stdio,h> void main() { int x = 0, y = 2, z = 3; int a = x & y | z; printf("%d", a); }

a)

3

b)

Run time error

c)

0

d)

2

32.

What will be the final value of j in the following C code? #include int main() { int i = 10, j = 0; if (i || (j = i + 10))

printf("%d",j) ; }

a)

0

b)

Depends on language standard

c)

20

d)

Compile time error

33.

What will be the output of the following C code? #include void main() { int x = 1, z = 3; int y = x << 3; printf(" %d\n", y); }

a)

8

b)

Run time error

c)

-2147483648

d)

-1

34.

What is the type of the following assignment expression if x is of type float and y is of type int? y = x + y;

a)

there is no type for an assignment expression

b)

double

c)

int

d)

float

35.

What will be the value of the following C expression? (x = foo()) != 1 considering foo() returns 2

a)

0

b)

True

c)

2

d)

1

36.

Operation "a = a * b + a" can also be written as ___________

a)

All of the mentioned

b)

a *= b + 1;

c)

(c = a * b)!=(a = c + a);

d)

a = (b + 1)* a;

37.

Which of the following is an invalid assignment operator?

a)

a /= 10;

b)

a %= 10;

c)

a |= 10;

d)

None of the mentioned

38.

What will be the output of the following C code? #include int main() { int a = 2; int b = 0; int y = (b == 0) ? a :(a > b) ? (b = 1): a; printf("%d\n", y); }

a)

2

b)

Compile time error

c)

Undefined behaviour

d)

1

39.

What is short int in C programming?

a)

Qualifier

b)

Short is the qualifier and int is the basic data type

c)

All of the mentioned

d)

The basic data type of C