0

Data Types, Variables and Storage Classes

Attempted 0/25 Correct 0 Score 0

What will be the output of the following C code? void main() { int t; char *pc=(char *)0; float *pf=(float *)0; t=(int)(pc+1) + (int)(pf+1); printf(%d,t); }

  1. 3

  2. 5

  3. 7

  4. 8


Correct Option: B
Explanation:

The initial address of char and float data types is 0. So, the values of (int)(pc+1) and (int)(pf+1) will be 1 and 4, respectively. Hence, the output of the code will be 5.

What will be the output of the following C code? int T; static T= 8; extern T; void main() { printf(%d,T); }

  1. 8

  2. 0

  3. Compile error

  4. Runtime error


Correct Option: A
Explanation:

More than one global variable declaration is allowed. But you can initialise only one variable. Hence, output will be 8.

What will be the output of the following C code? void main() { char ch=321; printf(%d %c,ch,ch); }

  1. 65 A

  2. 66 B

  3. 67 C

  4. 97 A


Correct Option: A
Explanation:

The value of ch is outside the range of char (-128 to +127). So, it goes to other the side and becomes 65. Hence, the ASCII value of 'A' = 65

What will be the output of following C code? void main() { int t,*pt; register int y,*py; pt=&t; py=&y; t=10; y=90; printf(%d %d,*pt,*py); }

  1. 10 90

  2. 90 10

  3. 10 10

  4. Compilation error


Correct Option: D
Explanation:

The register variable stores in Central Processing Unit (CPU). So, y does not have any memory location. Hence, py=&y is not a valid statement.

Find the output of the following C code. void main() { char Rch; int Rn; float Rr; printf(%d %d %d, sizeof(Rch),sizeof(Rn),sizeof(Rr)); }

  1. 1 1 1

  2. 1 2 4

  3. 1 2 2

  4. 2 4 4


Correct Option: B
Explanation:

Rch is a character variable and it occupies 1 byte. Rn is an integer variable and it occupies 2 bytes. Rr is a float variable and it occupies 4 bytes. Hence, the output will be 1 2 4. 

What will be the output of the following C code? void main() { static int t=7; printf(%d,t); if(t--) main(); }

  1. 76543210

  2. 7654321

  3. 7654321 - 1

  4. Infinite loop


Correct Option: A
Explanation:

First printf() will print 7, then if condition gets true due to non-zero integer and t will decrement and main() call recursively. Again printf() will print 6, then if condition gets true due to non zero integer and t will decrement and main() call recursively and so on. If condition gets false, when value of t will be 0. Hence, output will be 76543210. (The static variable always retains its value)

What will be the output of the following C code? void main() { int T='T'; printf(%c,T+6); }

  1. Z

  2. Y

  3. X

  4. W


Correct Option: A
Explanation:

The ASCII value of 'T' is 84. So, the value of T + 6 is 90. Hence, '%c' converts the integer 90 to character 'Z'.

If the input of the following program is 10, what will be the output? void print(int); void main() { int n; scanf(%d,&n); print(n); } void print(static int x) { int i; for(i=1;i<=x;i++) printf(%d,i); }

  1. 1 2 3 4 5 6 7 8 9 10

  2. 1 1 1 1 1 1 1 1 1 1

  3. 0 0 0 0 0 0 0 0 0 0

  4. Compile error


Correct Option: D
Explanation:

Here storage class static is not allowed. 

By which values are t and c initialized to print - 25536 and - 20536, respectively? void main() { int t=__,c=__; printf(%d %d,t,c); }

  1. 41000, 46000

  2. 40000, 46000

  3. 41000, 50000

  4. 40000, 45000


Correct Option: D
Explanation:

The range of int is - 32768 to + 32767. 40000 is exceeding + 32767 by 7233 and 45000 exceeding + 32767 by 12233. So, 7233th and 12233th integers from the other side of range is - 25536 and - 20536.

What will be the output of the following C code? void main() { printf(Hello ); printf(World); }

  1. Hello

  2. World

  3. Hello World

  4. HelloWorld


Correct Option: D

Which of the following symbols cannot print directly through printf statement?

  1. =

  2. >

  3. <


Correct Option: C
Explanation:

The printf statement cannot print double quotation mark ('') directly. The backward salash () is to be used before double quotation mark ('') to display. For example, printf(\'');

What error will occur while running the following program? void main() { int const *t=8; printf(%d,++(*t)); }

  1. Lvalue required

  2. Invalid pointer

  3. Cannot modify the constant object

  4. Runtime error


Correct Option: C
Explanation:

Here 't' is a pointer to a constant integer. But program wants to change the value of t by statement ++(*t), which is not possible. Hence, it will give the error 'Cannot modify the constant object'.

What will be the output of the following C code? void main() { int t=70,c=14,d; d=t/**//c; printf(%d,d); }

  1. 4

  2. 5

  3. 6

  4. 3


Correct Option: B
Explanation:

Here '/**/' is the comment and is the simple statement like d = t/c. Hence, it gives the output 5.

What will be the output of the following C code? void main() { double t=9.0,c=78.50; float Res; Res = (t+c)/8; printf(%.4f, Res); }

  1. 10

  2. 11

  3. 10.9000

  4. 10.9375


Correct Option: D
Explanation:

Res = (t+c)/8 = (9.0 + 78.50)/8 = 87.50/8 = 10.937500 Due to '%.4f', it will print 10.9375.

What is the return data type of printf() statement?

  1. Int

  2. float

  3. char

  4. double


Correct Option: A
Explanation:

The return data type of printf() statement is integer. It returns the integer, which represents the number of characters printed.

What error will occur while running the following program? void main() { int i=j+5,j=6; printf(%d %d,i,j); }

  1. Undefined Symbol i

  2. Lvalue required

  3. Undefined symbol j

  4. No error


Correct Option: C
Explanation:

'j' is used before the declaration. Hence, the compiler will give the 'Undefined symbol j' error.

What is the correct C language expression for the following mathematical expression? Sin2x + Cos2x + Sin(ex + log10x)

  1. pow(sinx,2) + cos(2*x) + sin(exp(x) + log10(x))

  2. pow(sin,2x) + cos(2*x) + sin(exp(x) + log10(x))

  3. pow(sinx,2) + cos(2x) + sin(exp(x) + log10(x))

  4. pow(sinx,2) + cos(2*x) + sin(exp(x) + log10(x))


Correct Option: D
Explanation:

For sinx, cosx, ex and log10x , the functions are sin(x), cos(x), exp(x) and log10(x), respectively. Hence, the correct expression is pow(sinx,2) + cos (2*x) + sin(exp(x) + log10(x)).

What will be the output of the following C code? void main() { int fact=1,i; clrscr(); for(i=2;i<=8;i++) fact=fact*i; printf(%d,fact); }

    • 25215
    • 25216
    • 25217
    • 25218

Correct Option: A
Explanation:

Factorial of 8 is out of range from the int data type (-32768 to +32767). Factorial of 8 is 40320, i.e. it goes to other end and displays the (40320 - 32767) = 7553th term from the -ve side. Hence, the output will be - 25216.

void main() { int i,n,sum=0; scanf(“%d”,&n); for(i=0;i<=n;i++) sum=sum+i; printf(“%d”,sum); } The above program is for sum of the numbers from 0 to n. What is the maximum value of n for which the program gives the desired output?

  1. 922

  2. 32767

  3. 923

  4. 999


Correct Option: A
Explanation:

The sum from 0 to 922 is 32287. If 923 is added with 32287, the sum will be 33210, which is outside the range of integer data type. Hence, n up to 922 can give the desired output.

Find out the error in the following program. void main() { int t,c; scanf(Enter the values of t and c = %d %d,&t,&c); printf(t=%d c=%d, t, c); }

  1. Compile error

  2. Linker error

  3. No error

  4. Runtime error


Correct Option: C
Explanation:

It runs properly if the message is to be typed as it is in the scanf() statement, and then enter the values of t and c. For example, After running the program: Enter the values of t and c = 45 67 The output will be t = 45 c = 67

Which of the following is a range of long signed int?

  1. -2147483648 to +2147483647

  2. -2147483647 to +2147483648

    • 2147483647 to + 2147483647
    • 32768 to + 32767

Correct Option: A
Explanation:

The range of long signed int is - 2147483648 to + 2147483647.

What will be the output of the following C code? void main() { int a; char *pr; int Num=288; pr=(char *)&Num; for(a=0;a<2;a++) printf(%d ,*pr++); }

  1. 288 0

  2. 32 1

  3. 0 1

  4. Compilation error


Correct Option: B
Explanation:

In C int, datatype is of 2 bytes while char pointer pt will take only one byte. Binary representation of 32 is 00000000 00100000.  The pr pointer will first point the second byte, and then the first byte. So, second byte will be represented by 00100000, i.e. 32 and first byte will be represented by 00000000, i.e. 0. Hence, the output will be 32 0.

Which of the following programs prints ABCDEFG?

  1. void main() { int i; for(i=65;i<=71;printf(%d,i),i++); }

  2. void main() { int i; for(i=65;i<=71;printf(%c,i)); }

  3. void main() { int i; for(i=65;i<=71;printf(%c,i),i++); }

  4. void main() { int i; for(i=65;i<=70;printf(%c,i),i++); }


Correct Option: C
Explanation:

Loop will execute for i = 65 to 71. The ASCII value of 'A' = 65 and ASCII value of 'G' = 71 Hence, the output will be “ABCDEFG”.

What type of error will occur while running the following program?

void main() { extern int t; t =100; printf(Value of t = %d,t); }

  1. Linker error

  2. Compilation error

  3. Runtime error

  4. No error


Correct Option: A
Explanation:

Here, 't' is the external variable and specifies to the compiler that the memory for 't' is allocated in some other program. Hence, linker error has occurred.

If any signed integer data type takes 4 bytes, what maximum value can be stored?

    • 24
    • 232 - 1
    • 231
    • 231 - 1

Correct Option: D
Explanation:

If any signed integer data type takes n bytes, the range of that data type will be -28n-1 to +28n-1 - 1. In this case, n = 4.  The maximum value stored = +28 x 4 - 1 - 1 = + 231 - 1

- Hide questions