Alien head

Programs in C

Description: Programs in C Java/Oracle /C/C++IT Certificate Programs
Number of Questions: 15
Created by:
Tags: Programs in C Java/Oracle /C/C++ IT Certificate Programs
Attempted 0/15 Correct 0 Score 0

void main() { printf("%d"t, sizeof(7.5)); printf("%d"t, sizeof(80000)); printf("%d"t, sizeof('B')); }.

Which of the following is the output of the program?

  1. 8, 2, 2

  2. 4, 4, 2

  3. 8, 4, 2

  4. Compilation error

  5. Runtime error


Correct Option: C
Explanation:

Sizeof operator is used to provide size of the given variable. Here, sizeof(7.5) provides the size 8 byte because it is a double type. Sizeof(80000) provides the size 4 byte because it is long int type. Sizeof ('B') provides the size 2 byte because it is a character type.

void 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); }.

Which of the following is the output of the program?

  1. Compilation error

  2. 0, 0

  3. 65536, 0

  4. Runtime error

  5. 65536, - 10


Correct Option: B
Explanation:

In any binary operation of dissimilar data type, 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. x= 10 + (-10u) + 10u + (-10) x= 10 + (-10) + 10 + (-10) x=0 so y=0

The most common use of one dimensional array in C is which of the following?

  1. Int

  2. Char

  3. Function

  4. String

  5. Void


Correct Option: D
Explanation:

The most common use of one dimensional array in C is string.

void main() { int i=3; int j, **k; j=&i; k=&j; printf("%u%u%d", k, *k, *k);}

  1. Address, address, 3

  2. Address, address, address

  3. 3, address, address

  4. Syntax error

  5. Runtime error


Correct Option: A
Explanation:

Here, you can see that * and & always cancel to each other. &a= a. So k= &j. It prints the address. *k= *(&j). Since, k= &j. So, *k= *&j= j= &i. It prints the address. *k= **(&j)= *j= *(&i)= i =3.

void main() { print("%d%d%d", sizeof(4.14), sizeof(4.14f), sizeof(4.14L)); }

  1. 10, 4, 10

  2. Lexical error

  3. Compile error

  4. 8, 4, 4

  5. 8, 4,10


Correct Option: E
Explanation:

4.14 is double type and its size is 8 byte. 4.14f is float type and its size is 4 byte. 4.14L is long double type and its size is 10 byte.

Which of the following is an integral data type?

  1. Float

  2. Char

  3. Double

  4. Return

  5. Void


Correct Option: B
Explanation:

It is an integral data type because it stores the ASCII value of any character constant.

void main() { volatile int a=12; printf("%d", a); }

  1. Can not predict

  2. 12

  3. Garbage value

  4. Compiler error

  5. Semantics error


Correct Option: A
Explanation:

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

Const enum Beta{x, y=4, z}p=11; void main() { enum Beta a, b; a=x; b=z; printf("%d", a+b-2p); }

  1. 10

  2. 15

    • 15
  3. Runtime error

  4. Syntax error


Correct Option: C
Explanation:

Default value of enum constant x is zero. z=y+1= 4+1= 5. So a+b-2p= 0+5-2*10= -15.

void main() { char x=260; int i; i=x + !x + ~x + ++x; printf("%d", i); }

    • 5
  1. 4

  2. Lexical error

    • 6
  3. Syntax error


Correct Option: D
Explanation:

Char a = 260. 260 is beyond the range of signed character. Its corresponding cyclic value is -6. a = -6. Operator !, ~ and ++ have equal precedence. First ++ operator performs, so its value is -5. i = -5 + !-5 + ~5 + -5 = -5+0+4-5 = -6.

void main() { int x; x=sizeof(!7.8); printf("%d",x); }

  1. 4

  2. 2

  3. 8

  4. 1

  5. 10


Correct Option: B
Explanation:

! is negation operator and it returns either integer 0 or 1. So, !7.8 = 0, and 0 is integer number and size of integer data type=2.

void main() { int a= 100; void *j= &a; int *k= j; printf("%u", *k); }

  1. Runtime error

  2. Compiler error

  3. Garbage value

  4. Address

  5. 100


Correct Option: E
Explanation:

Void pointer can hold address of any data type without type casting. Any pointer can hold void pointer without type casting. This program prints the result = 100.

void main() { int x; x=10, 20, 30; printf("%d", x); }

  1. 30

  2. 20

  3. 10

  4. Garbage value

  5. Lexical error


Correct Option: C
Explanation:

Assignment operator has more precedence than comma operator. So, = operator will be evaluated first.  Hence, 10 will be printed.

Which of the following creates a memory overlay area, with each union member using same memory storage locations?

  1. Array

  2. Union

  3. Structure

  4. Function

  5. Void


Correct Option: B
Explanation:

Union creates a memory overlay area, with each union member using same memory storage locations.

void main() { int x; x=1; x= 2 + 2 * x++; printf("%d", x); }

  1. 5

  2. 6

  3. 4

  4. Syntax error

  5. Runtime error


Correct Option: A
Explanation:

Here, x =1. So, x = 2 + 2*1 = 4. Now by postfix increment operator, i will be increment by 1. So, x = 4+1= 5.

Which of the following loops is called exit controlled loop?

  1. Do while

  2. While

  3. For

  4. Break

  5. Goto


Correct Option: A
Explanation:

This loop is called exit controlled loop because the condition is checked in the end, in do while loop.

+ View questions