Top Banner
DURGA SOFTAWARE SOLUTIONS CRT-C Language DURGA SOFTWARE SOLUTIONS, 23/3RT, 2 nd Floor. Opp: Reebok Shoe Room, Near Andhra Bank S.R Nagar, Hyderabad. Cell: 9246212143, Ph: 040-64512786 Page 1 EXPRESSIONS 1. Which of the following is the correct order of evaluation for the below expression? z = x + y * z / 4 % 2 - 1 A.* / % + - = B. = * %/ + - C. +*/%-= D.* /% - + = Answer & Explanation Answer: Option A Explanation: C uses left associatively for evaluating expressions to break a tie between two operators having same precedence 2. Which of the following correctly shows the hierarchy of arithmetic operations in C? A./ + * - B. * - / + C. + - / * D./ * + - Answer & Explanation Answer: Option D Explanation: Simply called as BODMAS (Bracket of Division, Multiplication, Addition and Subtraction). How Do I Remember ? BODMAS ! B ā€“ Brackets first O - Orders (ie Powers and Square Roots, etc.) (of) DM - Division and Multiplication (left-to-right) AS - Addition and Subtraction (left-to-right) 3. Which of the following is the correct usage of conditional operators used in C? A.a>b ? c=30 : c=40; B. a>b ? c=30; C. max = a>b ? a>c?a:c:b>c?b:c D.return (a>b)?(a:b) Answer & Explanation C
210

EXPRESSIONS - Google Groups

May 02, 2023

Download

Documents

Khang Minh
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: EXPRESSIONS - Google Groups

DURGA SOFTAWARE SOLUTIONS

CRT-C Language

DURGA SOFTWARE SOLUTIONS, 23/3RT, 2nd Floor. Opp: Reebok Shoe Room, Near Andhra Bank S.R Nagar, Hyderabad. Cell: 9246212143, Ph: 040-64512786 Page 1

EXPRESSIONS

1. Which of the following is the correct order of evaluation for the below expression?

z = x + y * z / 4 % 2 - 1

A. * / % + - = B. = * %/ + -

C. +*/%-= D. * /% - + =

Answer & Explanation

Answer: Option A

Explanation:

C uses left associatively for evaluating expressions to break a tie between two operators having

same precedence

2. Which of the following correctly shows the hierarchy of arithmetic operations in C?

A. / + * - B. * - / +

C. + - / * D. / * + -

Answer & Explanation

Answer: Option D

Explanation:

Simply called as BODMAS (Bracket of Division, Multiplication, Addition and Subtraction).

How Do I Remember ? BODMAS !

B ā€“ Brackets first

O - Orders (ie Powers and Square Roots, etc.) (of)

DM - Division and Multiplication (left-to-right)

AS - Addition and Subtraction (left-to-right)

3. Which of the following is the correct usage of conditional operators used in C?

A. a>b ? c=30 : c=40; B. a>b ? c=30;

C. max = a>b ? a>c?a:c:b>c?b:c D. return (a>b)?(a:b)

Answer & Explanation C

Page 2: EXPRESSIONS - Google Groups

DURGA SOFTAWARE SOLUTIONS

CRT-C Language

DURGA SOFTWARE SOLUTIONS, 23/3RT, 2nd Floor. Opp: Reebok Shoe Room, Near Andhra Bank S.R Nagar, Hyderabad. Cell: 9246212143, Ph: 040-64512786 Page 2

Answer: Option C

Explanation:

Option A: assignment statements are always return in paranthesis in the case of conditional

operator. It should be a>b? (c=30):(c=40);

Option B: it is syntatically wrong. It should have three arguments.

Option C: it uses nested conditional operator, this is logic for finding greatest number out of

three numbers.

Option D: syntatically wrong, it should be return (a>b ? a:b);

4. Which of the following are unary operators in C?

1. !

2. sizeof

3. ~

4. &&

A. 1, 2 B. 1, 3

C. 2, 4 D. 1, 2, 3

Answer & Explanation

Answer: Option D

Explanation:

An operation with only one operand is called unary operation.

Unary operators:

! Logical NOT operator.

~ bitwise NOT operator.

sizeof Size-of operator.

Binary Operator:

&& Logical AND

Therefore, 1, 2, 3 are unary operators.

5. In which order do the following gets evaluated

1. Relational

Page 3: EXPRESSIONS - Google Groups

DURGA SOFTAWARE SOLUTIONS

CRT-C Language

DURGA SOFTWARE SOLUTIONS, 23/3RT, 2nd Floor. Opp: Reebok Shoe Room, Near Andhra Bank S.R Nagar, Hyderabad. Cell: 9246212143, Ph: 040-64512786 Page 3

2. Arithmetic

3. Logical

4. Assignment

A. 2134 B. 1234

C. 4321 D. 3214

Answer & Explanation

Answer: Option A

Explanation:

1. Arithmetic operators: *, /, %, +, -

2. Relational operators: >, <, >=, <=, ==, !=

3. Logical operators : !, &&, ||

4. Assignment operators: =

6. What will be the output of the program?

#include<stdio.h>

int main()

{

int i=-3, j=2, k=0, m;

m = ++i && ++j && ++k;

printf("%d, %d, %d, %d\n", i, j, k, m);

return 0;

}

A. -2, 3, 1, 1 B. 2, 3, 1, 2

C. 1, 2, 3, 1 D. 3, 3, 1, 2

Answer & Explanation

Answer: Option A

Explanation:

Step 1: int i=-3, j=2, k=0, m; here variable i, j, k, m are declared as an integer type and variable

i, j, k are initialized to -3, 2, 0 respectively.

Step 2: m = ++i && ++j && ++k;

becomes m = -2 && 3 && 1;

becomes m = TRUE && TRUE; Hence this statement becomes TRUE. So it returns '1'(one).

Hence m=1.

Page 4: EXPRESSIONS - Google Groups

DURGA SOFTAWARE SOLUTIONS

CRT-C Language

DURGA SOFTWARE SOLUTIONS, 23/3RT, 2nd Floor. Opp: Reebok Shoe Room, Near Andhra Bank S.R Nagar, Hyderabad. Cell: 9246212143, Ph: 040-64512786 Page 4

Step 3: printf("%d, %d, %d, %d\n", i, j, k, m); In the previous step the value of i,j,k are

increemented by '1'(one).

Hence the output is "-2, 3, 1, 1".

7. Assunming, integer is 2 byte, What will be the output of the program?

#include<stdio.h>

int main()

{

printf("%x\n", -2<<2);

return 0;

}

A. ffff B. 0

C. fff8 D. Error

Answer & Explanation

Answer: Option C

Explanation:

Step 1: printf("%x\n", -2<<2); here -2 is left shifted 2 bits.

Binary value of -2 is 1111 1111 1111 1110

After left shifting 2 bits 1111 1111 1111 1000 gives -8

printf("%x\n", -8); prints -8 in hexadecimal format.

Hence the output is fff8.

8. What will be the output of the program?

#include<stdio.h>

int main()

{

int i=-3, j=2, k=0, m;

m = ++i || ++j && ++k;

printf("%d, %d, %d, %d\n", i, j, k, m);

return 0;

}

A. 2, 2, 0, 1 B. 1, 2, 1, 0

C. -2, 2, 0, 0 D. -2, 2, 0, 1

Page 5: EXPRESSIONS - Google Groups

DURGA SOFTAWARE SOLUTIONS

CRT-C Language

DURGA SOFTWARE SOLUTIONS, 23/3RT, 2nd Floor. Opp: Reebok Shoe Room, Near Andhra Bank S.R Nagar, Hyderabad. Cell: 9246212143, Ph: 040-64512786 Page 5

Answer & Explanation

Answer: Option D

Explanation:

Step 1: int i=-3, j=2, k=0, m; here variable i, j, k, m are declared as an integer type and variable

i, j, k are initialized to -3, 2, 0 respectively.

Step 2: m = ++i || ++j && ++k; here (++j && ++k;) this code will not get executed because

++i has non-zero value.

becomes m = -2 || ++j && ++k;

becomes m = TRUE || ++j && ++k; Hence this statement becomes TRUE. So it returns

'1'(one). Hence m=1.

Step 3: printf("%d, %d, %d, %d\n", i, j, k, m); In the previous step the value of variable 'i' only

increemented by '1'(one). The variable j,k are not increemented.

Hence the output is "-2, 2, 0, 1"

9. What will be the output of the program?

#include<stdio.h>

int main()

{

int x=2, y=70, z;

z = x!=4 || y == 2;

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

return 0;

}

A. z=0 B. z=1

C. z=4 D. z=2

Answer & Explanation

Answer: Option B

Explanation:

Step 1: int x=2, y=70, z; here variable x, y and z are declared as an integer and variable x and y

are initialized to 2, 70 respectively.

Step 2: z = x!=4 || y == 2;

becomes z = 2!=4 || 70 == 2;

then z = (condition true) || (condition false); Hence it returns 1. So the value of z=1.

Page 6: EXPRESSIONS - Google Groups

DURGA SOFTAWARE SOLUTIONS

CRT-C Language

DURGA SOFTWARE SOLUTIONS, 23/3RT, 2nd Floor. Opp: Reebok Shoe Room, Near Andhra Bank S.R Nagar, Hyderabad. Cell: 9246212143, Ph: 040-64512786 Page 6

Step 3: printf("z=%d\n", z); Hence the output of the program is "z=1".

10. What will be the output of the program?

#include<stdio.h>

int main()

{

static int a[5];

int i = 0;

a[i] = i ;

printf("%d, %d, %d\n", a[0], a[1], i);

return 0;

}

A. 1, 0, 1 B. 1, 1, 1

C. 0, 0, 0 D. 0, 1, 0

Answer & Explanation

Answer: Option C

Explanation:

Step 1: static int a[5]; here variable a is declared as an integer type and static. If a variable is

declared as static and it will ne automatically initialized to value '0'(zero).

Step 2: int i = 0; here vaiable i is declared as an integer type and initialized to '0'(zero).

Step 3: a[i] = i ; becomes a[0] = 0;

Step 4: printf("%d, %d, %d\n", a[0], a[1], i);

Here a[0] = 0, a[1] = 0(because all staic variables are initialized to '0') and i = 0.

Step 4: Hence the output is "0, 0, 0".

11. What will be the output of the program?

#include<stdio.h>

int main()

{

int i=4, j=-1, k=0, w, x, y, z;

w = i || j || k;

x = i && j && k;

y = i || j &&k;

z = i && j || k;

printf("%d, %d, %d, %d\n", w, x, y, z);

return 0;

}

A. 1, 1, 1, 1 B. 1, 1, 0, 1

C. 1, 0, 0, 1 D. 1, 0, 1, 1

Page 7: EXPRESSIONS - Google Groups

DURGA SOFTAWARE SOLUTIONS

CRT-C Language

DURGA SOFTWARE SOLUTIONS, 23/3RT, 2nd Floor. Opp: Reebok Shoe Room, Near Andhra Bank S.R Nagar, Hyderabad. Cell: 9246212143, Ph: 040-64512786 Page 7

Answer & Explanation

Answer: Option D

Explanation:

Step 1: int i=4, j=-1, k=0, w, x, y, z; here variable i, j, k, w, x, y, z are declared as an integer type

and the variable i, j, k are initialized to 4, -1, 0 respectively.

Step 2: w = i || j || k; becomes w = 4 || -1 || 0;. Hence it returns TRUE. So, w=1

Step 3: x = i && j && k; becomes x = 4 && -1 && 0; Hence it returns FALSE. So, x=0

Step 4: y = i || j &&k; becomes y = 4 || -1 && 0; Hence it returns TRUE. So, y=1

Step 5: z = i && j || k; becomes z = 4 && -1 || 0; Hence it returns TRUE. So, z=1.

Step 6: printf("%d, %d, %d, %d\n", w, x, y, z); Hence the output is "1, 0, 1, 1".

12. What will be the output of the program?

#include<stdio.h>

int main()

{

int i=-3, j=2, k=0, m;

m = ++i && ++j || ++k;

printf("%d, %d, %d, %d\n", i, j, k, m);

return 0;

}

A. 1, 2, 0, 1 B. -3, 2, 0, 1

C. -2, 3, 0, 1 D. 2, 3, 1, 1

Answer & Explanation

Answer: Option C

Explanation:

Step 1: int i=-3, j=2, k=0, m; here variable i, j, k, m are declared as an integer type and variable

i, j, k are initialized to -3, 2, 0 respectively.

Step 2: m = ++i && ++j || ++k;

becomes m = (-2 && 3) || ++k;

becomes m = TRUE || ++k;.

Page 8: EXPRESSIONS - Google Groups

DURGA SOFTAWARE SOLUTIONS

CRT-C Language

DURGA SOFTWARE SOLUTIONS, 23/3RT, 2nd Floor. Opp: Reebok Shoe Room, Near Andhra Bank S.R Nagar, Hyderabad. Cell: 9246212143, Ph: 040-64512786 Page 8

(++k) is not executed because (-2 && 3) alone return TRUE.

Hence this statement becomes TRUE. So it returns '1'(one). Hence m=1.

Step 3: printf("%d, %d, %d, %d\n", i, j, k, m); In the previous step the value of i,j are

increemented by '1'(one).

Hence the output is "-2, 3, 0, 1".

13. What will be the output of the program?

#include<stdio.h>

int main()

{

int x=4, y, z;

y = --x;

z = x--;

printf("%d, %d, %d\n", x, y, z);

return 0;

}

A. 4, 3, 3 B. 4, 3, 2

C. 3, 3, 2 D. 2, 3, 3

Answer & Explanation

Answer: Option D

Explanation:

Step 1: int x=4, y, z; here variable x, y, z are declared as an integer type and variable x is

initialized to 4.

Step 2: y = --x; becomes y = 3; because (--x) is pre-increement operator.

Step 3: z = x--; becomes z = 3;. In the next step variable x becomes 2, because (x--) is post-

increement operator.

Step 4: printf("%d, %d, %d\n", x, y, z); Hence it prints "2, 3, 3".

14. What will be the output of the program?

#include<stdio.h>

int main()

{

int x=55;

printf("%d, %d, %d\n", x<=55, x=40, x>=10);

return 0;

}

A. 1, 40, 1 B. 1, 55, 1

C. 1, 55, 0 D. 1, 1, 1

Page 9: EXPRESSIONS - Google Groups

DURGA SOFTAWARE SOLUTIONS

CRT-C Language

DURGA SOFTWARE SOLUTIONS, 23/3RT, 2nd Floor. Opp: Reebok Shoe Room, Near Andhra Bank S.R Nagar, Hyderabad. Cell: 9246212143, Ph: 040-64512786 Page 9

Answer: Option A

Explanation:

Step 1: int x=55; here variable x is declared as an integer type and initialized to '55'.

Step 2: printf("%d, %d, %d\n", x<=55, x=40, x>=10);

The order of evaluation of printf is from right to left

x>=10 (55>=10) returns TRUE. hence it prints '1'.

x=40 here x is assigned to 40 Hence it prints '40'.

here x<=55 (40<=55) returns TRUE hence it prints '1'.

Step 3: Hence the output is "1, 40, 1".

15. What will be the output of the program?

#include<stdio.h>

int main()

{

int i=2;

printf("%d, %d\n", ++i, ++i);

return 0;

}

A. 3, 4

B. 4, 3

C. 4, 4

D. Output may vary from compiler to compiler

Answer & Explanation

Answer: Option D

Explanation:

The order of evaluation of arguments passed to a function call is unspecified.

Anyhow, we consider ++i, ++i are Right-to-Left associativity. The output of the program is 4,

3.

In TurboC, the output will be 4, 3.

In GCC, the output will be 4, 4.

16. What will be the output of the program?

#include<stdio.h>

int main()

Page 10: EXPRESSIONS - Google Groups

DURGA SOFTAWARE SOLUTIONS

CRT-C Language

DURGA SOFTWARE SOLUTIONS, 23/3RT, 2nd Floor. Opp: Reebok Shoe Room, Near Andhra Bank S.R Nagar, Hyderabad. Cell: 9246212143, Ph: 040-64512786 Page 10

{

int k, num=30;

k = (num>5 ? num <=10 ? 100 : 200: 500);

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

return 0;

}

A. 200 B. 30

C. 100 D. 500

Answer & Explanation

Answer: Option B

Explanation:

Step 1: int k, num=30; here variable k and num are declared as an integer type and variable num

is initialized to '30'.

Step 2: k = (num>5 ? num <=10 ? 100 : 200: 500); This statement does not affect the output of

the program. Because we are going to print the variable num in the next statement. So, we skip

this statement.

Step 3: printf("%d\n", num); It prints the value of variable num '30'

Step 3: Hence the output of the program is '30'

17. What will be the output of the program?

#include<stdio.h>

int main()

{

char ch;

ch = 'A';

printf("The letter is");

printf("%c", ch >= 'A' && ch <= 'Z' ? ch + 'a' - 'A':ch);

printf("Now the letter is");

printf("%c\n", ch >= 'A' && ch <= 'Z' ? ch : ch + 'a' - 'A');

return 0;

}

A.

The letter is a

Now the letter is A B.

The letter is A

Now the letter is a

C. Error D. None of above

Answer & Explanation

Answer: Option A

Explanation:

Page 11: EXPRESSIONS - Google Groups

DURGA SOFTAWARE SOLUTIONS

CRT-C Language

DURGA SOFTWARE SOLUTIONS, 23/3RT, 2nd Floor. Opp: Reebok Shoe Room, Near Andhra Bank S.R Nagar, Hyderabad. Cell: 9246212143, Ph: 040-64512786 Page 11

Step 1: char ch; ch = 'A'; here variable ch is declared as an character type an initialized to 'A'.

Step 2: printf("The letter is"); It prints "The letter is".

Step 3: printf("%c", ch >= 'A' && ch <= 'Z' ? ch + 'a' - 'A':ch);

The ASCII value of 'A' is 65 and 'a' is 97.

Here

=> ('A' >= 'A' && 'A' <= 'Z') ? (A + 'a' - 'A'):('A')

=> (TRUE && TRUE) ? (65 + 97 - 65) : ('A')

=> (TRUE) ? (97): ('A')

In printf the format specifier is '%c'. Hence prints 97 as 'a'.

Step 4: printf("Now the letter is"); It prints "Now the letter is".

Step 5: printf("%c\n", ch >= 'A' && ch <= 'Z' ? ch : ch + 'a' - 'A');

Here => ('A' >= 'A' && 'A' <= 'Z') ? ('A') : (A + 'a' - 'A')

=> (TRUE && TRUE) ? ('A') :(65 + 97 - 65)

=> (TRUE) ? ('A') : (97)

It prints 'A'

Hence the output is

The letter is a

Now the letter is A

18. What will be the output of the program?

#include<stdio.h>

int main()

{

int i=20;

int j = i + (1, 2, 3, 4, 5);

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

return 0;

}

Page 12: EXPRESSIONS - Google Groups

DURGA SOFTAWARE SOLUTIONS

CRT-C Language

DURGA SOFTWARE SOLUTIONS, 23/3RT, 2nd Floor. Opp: Reebok Shoe Room, Near Andhra Bank S.R Nagar, Hyderabad. Cell: 9246212143, Ph: 040-64512786 Page 12

A. 21 B. 25

C. Garbage value D. error

Answer & Explanation

Answer: Option B

Explanation:

Because, comma operator used in the expression i (1, 2, 3, 4, 5). The comma operator has left-

right associativity. The left operand is always evaluated first, and the result of evaluation is

discarded before the right operand is evaluated. In this expression 5 is the right most operand,

hence after evaluating expression (1, 2, 3, 4, 5) the result is 5, which on adding to i results into

25.

19. Associativity has no role to play unless the precedence of operator is same.

A. True B. False

Answer & Explanation

Answer: Option A

Explanation:

Associativity is only needed when the operators in an expression have the same precedence.

Usually + and - have the same precedence.

Consider the expression 7 - 4 + 2. The result could be either (7 - 4) + 2 = 5 or 7 - (4 + 2) = 1.

The former result corresponds to the case when + and - are left-associative, the latter to when +

and - are right-associative.

Usually the addition, subtraction, multiplication, and division operators are left-associative,

while the exponentiation, assignment and conditional operators are right-associative. To prevent

cases where operands would be associated with two operators, or no operator at all, operators

with the same precedence must have the same associativity.

20. The expression of the right hand side of || operators doesn't get evaluated if the left hand side

determines the outcome.

A. True B. False

Answer & Explanation

Answer: Option A

Page 13: EXPRESSIONS - Google Groups

DURGA SOFTAWARE SOLUTIONS

CRT-C Language

DURGA SOFTWARE SOLUTIONS, 23/3RT, 2nd Floor. Opp: Reebok Shoe Room, Near Andhra Bank S.R Nagar, Hyderabad. Cell: 9246212143, Ph: 040-64512786 Page 13

Explanation:

Because, if a is non-zero then b will not be evaluated in the expression (x || y)

&& || are called short circuit operators.

21. In the expression a=b=c=50 the order of Assignment is NOT decided by Associativity of

operators

A. True B. False

Answer & Explanation

Answer: Option B

Explanation:

The equal to = operator has Right-to-Left Associativity. So it assigns c=50, b=c then a=b.

22. Associativity of an operator is either Left to Right or Right to Left.

A. True B. False

Answer & Explanation

Answer: Option A

Explanation:

Yes, the associativity of an operator is either Left to Right or Right to Left.

For example */%+- have left to right

= += -= !~have right to left

Page 14: EXPRESSIONS - Google Groups

DURGA SOFTAWARE SOLUTIONS

CRT-C Language

DURGA SOFTWARE SOLUTIONS, 23/3RT, 2nd Floor. Opp: Reebok Shoe Room, Near Andhra Bank S.R Nagar, Hyderabad. Cell: 9246212143, Ph: 040-64512786 Page 14

Declarations & Initializations 1. Which of the following statements should be used to obtain a remainder after dividing 3.5 by

2.5 ?

A. rem = 3.5 % 2.5;

B. rem = modf(3.5, 2.5);

C. rem = fmod(3.5, 2.5);

D. Remainder cannot be obtain in floating point division.

Answer: Option C

Explanation:

fmod(x,y) - Calculates x modulo y, the remainder of x/y.

This function is the same as the modulus operator. But fmod() performs floating point divisions.

2. What are the types of linkages?

A. Internal and External B. External, Internal and None

C. External and None D. Internal

Answer: Option B

Explanation:

External Linkage-> means global, non-static variables and functions.

Internal Linkage-> means static variables and functions with file scope.

None Linkage-> means Local variables.

3. Which of the following special symbol allowed in a variable?

A. * (asterisk) B. $ (Dollar)

C. # (Hash) D. _ (underscore)

Answer: Option D

Explanation:

Variable names in C are made up of letters (upper and lower case) and digits. The underscore

character ("_") is also permitted. Names must not begin with a digit.

Examples of valid (but not very descriptive) C variable names:

=> foo

=> Bar

=> BAZ

Page 15: EXPRESSIONS - Google Groups

DURGA SOFTAWARE SOLUTIONS

CRT-C Language

DURGA SOFTWARE SOLUTIONS, 23/3RT, 2nd Floor. Opp: Reebok Shoe Room, Near Andhra Bank S.R Nagar, Hyderabad. Cell: 9246212143, Ph: 040-64512786 Page 15

=> foo_bar

=> _foo42

=> _

=> QuUx

4. Is there any difference between following declarations?

1 : extern int f1();

2 : int f1();

A. Both are identical

B. No difference, except extern int f1(); is probably in another file

C. int f1(); is overrided with extern int f1();

D. None of these

Answer: Option B

Explanation:

extern int f1(); declaration in C is to indicate the existence of a global function and it is defined

externally to the current module or in another file.

int f1(); declaration in C is to indicate the existence of a function inside the current module or in

the same file

5. How would you round off a value from 2.75 to 3.0?

A. ceil(2.75) B. floor(2.75)

C. roundup(2.75) D. roundto(2.75)

Answer: Option A

Explanation:/* Example for ceil() and floor() functions: */

#include<stdio.h>

#include<math.h>

int main()

{

printf("\n Result : %f" , ceil(2.75) );

printf("\n Result : %f" , floor(2.75) );

return 0;

Page 16: EXPRESSIONS - Google Groups

DURGA SOFTAWARE SOLUTIONS

CRT-C Language

DURGA SOFTWARE SOLUTIONS, 23/3RT, 2nd Floor. Opp: Reebok Shoe Room, Near Andhra Bank S.R Nagar, Hyderabad. Cell: 9246212143, Ph: 040-64512786 Page 16

}

// Output: Result : 3.000000

// Output: Result : 2.000000

6. By default a real number is treated as a

A. float B. double

C. long double D. far double

Answer: Option B

Explanation:

In computing, 'real number' often refers to non-complex floating-point numbers. It include both

rational numbers, such as 42 and 3/4, and irrational numbers such as pi = 3.14159265...

When the accuracy of the floating point number is insufficient, we can use the double to define

the number. The double is same as float but with longer precision and takes double space (8

bytes) than float.

To extend the precision further we can use long double which occupies 10 bytes of memory

space.

7. Which of the following is not user defined data type?

1 : struct book

{

char name[10];

float price;

int pages;

};

2: long int l = 2L;

3: enum day {Sun, Mon, Tue, Wed};

4: union employee

{

int id;

Char name[36];

int sal;

};

Page 17: EXPRESSIONS - Google Groups

DURGA SOFTAWARE SOLUTIONS

CRT-C Language

DURGA SOFTWARE SOLUTIONS, 23/3RT, 2nd Floor. Opp: Reebok Shoe Room, Near Andhra Bank S.R Nagar, Hyderabad. Cell: 9246212143, Ph: 040-64512786 Page 17

A. 1 B. 2 C. 3 D. 4

Answer: Option B

Explanation:

C data types classification are

1. Primary data types

1. int

2. char

3. float

4. double

5. void

2. Secondary data types (or) User-defined data type

1. Array

2. Pointer

3. Structure

4. Union

5. Enum

So, clearly long int l = 2L; is not User-defined data type.

(i.e.long int l = 2L; is the answer.)

8. Is the following statement a declaration or definition?

extern int i;

A. Declaration B. Definition &Defination

C. Function D. Defination

Answer: Option A

Explanation:

Declaring is the way a programmer tells the compiler to expect a particular type, be it a variable,

class/struct/union type, a function type (prototype) or a particular object instance. (ie. extern int

i)

Declaration never reserves any space for the variable or instance in the program's memory; it

simply a "hint" to the compiler that a use of the variable or instance is expected in the program.

This hinting is technically called "forward reference".

9. Identify which of the following are declarations

1 : extern int exe;

2 : void square ( float x ) { ... }

Page 18: EXPRESSIONS - Google Groups

DURGA SOFTAWARE SOLUTIONS

CRT-C Language

DURGA SOFTWARE SOLUTIONS, 23/3RT, 2nd Floor. Opp: Reebok Shoe Room, Near Andhra Bank S.R Nagar, Hyderabad. Cell: 9246212143, Ph: 040-64512786 Page 18

3 : double pow(double, double);

A. 1 B. 2

C. 1 and 3 D. 3

Answer: Option C

Explanation:

extern int exe; - is an external variable declaration.

double pow(double, double); - is a function prototype declaration.

Therefore, 1 and 3 are declarations. 2 is definition.

10. In the following program where is the variable a getting defined and where it is getting

declared?

#include<stdio.h>

int main()

{

extern int a;

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

return 0;

}

int a=10;

A. extern int a is declaration, int a = 10 is the definition

B. int a = 10 is declaration, extern int a is the definition

C. int a = 10 is definition, a is not defined

D. a is declared, a is not defined

Answer: Option A

Explanation:

- During declaration we tell the datatype of the Variable( Just giving hint to the compiler, just

like function prototype).

- During definition the memory is allocated value is initialized.

11. When we mention the prototype of a function?

A. Defining B. Declaring

C. Prototyping D. invoking

Answer: Option B

Page 19: EXPRESSIONS - Google Groups

DURGA SOFTAWARE SOLUTIONS

CRT-C Language

DURGA SOFTWARE SOLUTIONS, 23/3RT, 2nd Floor. Opp: Reebok Shoe Room, Near Andhra Bank S.R Nagar, Hyderabad. Cell: 9246212143, Ph: 040-64512786 Page 19

Explanation:

A function prototype in C or C++ is a declaration of a function that omits the function body but

does specify the function's name, argument types and return type.

While a function definition specifies what a function does, a function prototype can be thought of

as specifying its interface.

12. What is the output of the program

#include<stdio.h>

int main()

{

enum status { pass, fail, atkt};

enum status stud1, stud2, stud3;

stud1 = pass;

stud2 = atkt;

stud3 = fail;

printf("%d, %d, %d\n", stud1, stud2, stud3);

return 0;

}

A. 0, 2, 1 B. 1, 2, 3

C. error D. 0,0,0

Answer: Option A

Explanation:

enum takes the format like {0,1,2..) so pass=0, fail=1, atkt=2

stud1 = pass (value is 0)

stud2 = atkt (value is 2)

stud3 = fail (value is 1)

Hence it prints 0, 2, 1

13. What will be the output of the program?

#include<stdio.h>

int main()

{

extern int i;

i = 20;

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

return 0;

Page 20: EXPRESSIONS - Google Groups

DURGA SOFTAWARE SOLUTIONS

CRT-C Language

DURGA SOFTWARE SOLUTIONS, 23/3RT, 2nd Floor. Opp: Reebok Shoe Room, Near Andhra Bank S.R Nagar, Hyderabad. Cell: 9246212143, Ph: 040-64512786 Page 20

}

A. 20

B. Garbage value

C. Compiler error

D. Linker Error : Undefined symbol 'i'

Answer: Option D

Explanation:

Linker Error : Undefined symbol 'i'

The statement extern int i specifies to the compiler that the memory for 'i' is allocated in some

other program and that address will be given to the current program at the time of linking. But

linker finds that no other variable of name 'i' is available in any other program with memory

space allocated for it. Hence a linker error has occurred.

14. What is the output of the program?

#include<stdio.h>

int main()

{

extern int exe;

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

return 0;

}

int exe=10;

A. 10 B. 0

C. Garbage Value D. Linker Error

15. What is the output of the program

#include<stdio.h>

int main()

{

char *s1;

char far *s2;

char huge *s3;

printf("%d, %d, %d\n", sizeof(s1), sizeof(s2), sizeof(s3));

return 0;

}

A. 2, 4, 6 B. 4, 4, 2

C. 2, 4, 4 D. 2, 2, 2

Answer: Option C

Page 21: EXPRESSIONS - Google Groups

DURGA SOFTAWARE SOLUTIONS

CRT-C Language

DURGA SOFTWARE SOLUTIONS, 23/3RT, 2nd Floor. Opp: Reebok Shoe Room, Near Andhra Bank S.R Nagar, Hyderabad. Cell: 9246212143, Ph: 040-64512786 Page 21

Explanation:

Any pointer size is 2 bytes. (only 16-bit offset)

So, char *s1 = 2 bytes.

So, char far *s2; = 4 bytes.

So, char huge *s3; = 4 bytes.

A far, huge pointer has two parts: a 16-bit segment value and a 16-bit offset value. Since C is a

compiler dependent language, it may give different output in other platforms. The above

program works fine in Windows (Turbo C), but error in Linux (GCC Compiler).

16. What is the output of the program

#include<stdio.h>

int main()

{

struct emp

{

char name[20];

int age;

float sal;

};

struct emp e = {"Tiger"};

printf("%d, %f\n", e.age, e.sal);

return 0;

}

A. 0, 0.000000 B. Garbage values

C. Error D. None of above

Answer: Option A

Explanation:

When an automatic structure is partially initialized remaining elements are initialized to 0(zero).

17. What will be the output of the program?

#include<stdio.h>

int X=10;

int main()

{

int X=20;

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

return 0;

}

A. 20 B. 10

Page 22: EXPRESSIONS - Google Groups

DURGA SOFTAWARE SOLUTIONS

CRT-C Language

DURGA SOFTWARE SOLUTIONS, 23/3RT, 2nd Floor. Opp: Reebok Shoe Room, Near Andhra Bank S.R Nagar, Hyderabad. Cell: 9246212143, Ph: 040-64512786 Page 22

C. 0 D.

Error due to conflict between local and global

variable

Answer: Option A

Explanation:

Whenever there is conflict between a local variable and global variable, the local variable gets

priority.

18. #include<stdio.h>

int main()

{

int x = 10, y = 20, z = 5, i;

i = x < y < z;

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

return 0;

}

A. 0 B. 1

C. Error D. Garbage value

Answer: Option B

Explanation:

Since x < y turns to be TRUE it is replaced by 1. Then 1 < z is compared and to be TRUE. The 1

is assigned to i.

19. What is the output of the program

#include<stdio.h>

int main()

{

extern int fun(float);

int a;

a = fun(3.14);

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

return 0;

}

int fun(aa)

float aa;

{

return ((int)aa);

}

Page 23: EXPRESSIONS - Google Groups

DURGA SOFTAWARE SOLUTIONS

CRT-C Language

DURGA SOFTWARE SOLUTIONS, 23/3RT, 2nd Floor. Opp: Reebok Shoe Room, Near Andhra Bank S.R Nagar, Hyderabad. Cell: 9246212143, Ph: 040-64512786 Page 23

A. 3 B. 3.14

C. 0 D. Error

Answer: Option D

Explanation:

2 Errors

1. Type mismatch in redeclaration of fun

2. Type mismatch in parameter aa

20. hat is the output of the program

#include<stdio.h>

int main()

{

int a[5] = {1,2};

printf("%d, %d, %d\n", a[2], a[3], a[4]);

return 0;

}

A. Garbage Values B. 2, 3, 3

C. Array should be completely initialized D. 0, 0, 0

Answer: Option D

Explanation:

When an automatic array is partially initialized, the remaining elements are initialized to 0.

21. What is the output of the program

#include<stdio.h>

int main()

{

union a

{

int i;

char ch[2];

};

union a u;

u.ch[0] = 3;

u.ch[1] = 2;

printf("%d, %d, %d\n", u.ch[0], u.ch[1], u.i);

return 0;

}

Page 24: EXPRESSIONS - Google Groups

DURGA SOFTAWARE SOLUTIONS

CRT-C Language

DURGA SOFTWARE SOLUTIONS, 23/3RT, 2nd Floor. Opp: Reebok Shoe Room, Near Andhra Bank S.R Nagar, Hyderabad. Cell: 9246212143, Ph: 040-64512786 Page 24

A. 3, 2, 515 B. 515, 2, 3

C. 3, 2, 5 D. Garbage values

Answer: Option A

Explanation:

printf("%d, %d, %d\n", u.ch[0], u.ch[1], u.i); It prints the value of u.ch[0] = 3, u.ch[1] = 2 and

it prints the value of u.i means the value of entire union size.

So the output is 3, 2, 515.

22. In the following program how long will the for loop get executed?

#include<stdio.h>

int main()

{

int i;

for(;scanf("%s", &i); printf("%d\n", i));

return 0;

}

A. The for loop would not get executed at all

B. The for loop would get executed only once

C. The for loop would get executed 5 times

D. The for loop would get executed infinite times

Answer: Option D

Page 25: EXPRESSIONS - Google Groups

DURGA SOFTAWARE SOLUTIONS

CRT-C Language

DURGA SOFTWARE SOLUTIONS, 23/3RT, 2nd Floor. Opp: Reebok Shoe Room, Near Andhra Bank S.R Nagar, Hyderabad. Cell: 9246212143, Ph: 040-64512786 Page 25

Explanation:

During the for loop execution scanf() ask input and then printf() prints that given input. This

process will be continued repeatedly because, scanf() returns the number of input given, the

condition is always true(user gives a input means it reurns '1').

Hence this for loop would get executed infinite times.

23. What will be the output of the program?

#include<stdio.h>

int main()

{

int X=40;

{

int X=20;

printf("%d ", X);

}

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

return 0;

}

A. 40 40 B. 20 40

C. 20 20 D. Error

Answer: Option B

Explanation:

In case of a conflict between a local variable and global variable, the local variable gets priority.

24. Point out the error in the following program.

#include<stdio.h>

int main()

{

display();

return 0;

}

void display()

{

printf("Disp fun");

}

A. No error

B. Disp fun

C. Compilation error: Type mismatch in redeclaration of function display()

Page 26: EXPRESSIONS - Google Groups

DURGA SOFTAWARE SOLUTIONS

CRT-C Language

DURGA SOFTWARE SOLUTIONS, 23/3RT, 2nd Floor. Opp: Reebok Shoe Room, Near Andhra Bank S.R Nagar, Hyderabad. Cell: 9246212143, Ph: 040-64512786 Page 26

D. None of these

Answer: Option C

Explanation:

In this program the compiler will not know that the function display() exists. So, the compiler

will generate "Type mismatch in redeclaration of function display()".

To overcome this error, we have to add function prototype of function display().

Another way to overcome this error is to define the function display() before the int main();

function.

#include<stdio.h>

void display(); /* function prototype */

int main()

{

display();

return 0;

}

void display()

{

printf("Disp fun");

}

Output: Disp fun

Note: This problem will not occur in modern compilers (this problem occurs in TurboC but not

in GCC).

25. Point out the error in the following program.

#include<stdio.h>

int main()

{

void v = 0;

printf("%d", v);

return 0;

}

A. Error: Declaration syntax error 'v' (or) Size of v is unknown or zero.

B. Program terminates abnormally.

Page 27: EXPRESSIONS - Google Groups

DURGA SOFTAWARE SOLUTIONS

CRT-C Language

DURGA SOFTWARE SOLUTIONS, 23/3RT, 2nd Floor. Opp: Reebok Shoe Room, Near Andhra Bank S.R Nagar, Hyderabad. Cell: 9246212143, Ph: 040-64512786 Page 27

C. No error.

D. None of these.

Answer: Option A

Explanation:

1. We can create void pointer but we canā€Ÿt create void variable.

2. There is no size for void variable so variable creation is not possible

26. Point out the error in the following program.

#include<stdio.h>

struct emp

{

char name[20];

int age;

};

int main()

{

emp int xx;

int a;

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

return 0;

}

A. Error: in printf B. Error: in emp int xx;

C. No error. D. None of these.

Answer: Option B

Explanation:

There is an error in the line emp int xx;

To overcome this error, remove the int and add the struct at the begining of emp int xx;

#include<stdio.h>

struct emp

{

char name[20];

int age;

};

int main()

{

struct emp xx;

int a;

Page 28: EXPRESSIONS - Google Groups

DURGA SOFTAWARE SOLUTIONS

CRT-C Language

DURGA SOFTWARE SOLUTIONS, 23/3RT, 2nd Floor. Opp: Reebok Shoe Room, Near Andhra Bank S.R Nagar, Hyderabad. Cell: 9246212143, Ph: 040-64512786 Page 28

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

return 0;

}

27. Which of the following is correct about err used in the declaration given below?

typedef enum error { warning, test, exception } err;

A. It is a typedef for enum error.

B. It is a variable of type enum error.

C. The statement is erroneous.

D. It is a structure.

Answer: Option A

Explanation:

A typedef gives a new name to an existing data type.

So err is a new name for enum error.

28. Point out the error in the following program.

#include<stdio.h>

int main()

{

int (*p)() = fun;

(*p)();

return 0;

}

int fun()

{

printf("Durga exams\n");

return 0;

}

A. Error: in int(*p)() = fun;

B. Error: fun() prototype not defined

C. No error

D. None of these

Answer: Option B

Page 29: EXPRESSIONS - Google Groups

DURGA SOFTAWARE SOLUTIONS

CRT-C Language

DURGA SOFTWARE SOLUTIONS, 23/3RT, 2nd Floor. Opp: Reebok Shoe Room, Near Andhra Bank S.R Nagar, Hyderabad. Cell: 9246212143, Ph: 040-64512786 Page 29

Explanation:

The compiler will not know that the function int fun() exists. So we have to define the function

prototype of int fun();

To overcome this error, see the below program

#include<stdio.h>

int fun(); /* function prototype */

int main()

{

int (*p)() = fun;

(*p)();

return 0;

}

int fun()

{

printf("Durga exams\n");

return 0;

}

29. Which of the definition is correct?

A. int len; B. char int;

C. int long; D. float double;

Answer: Option A

Explanation:

int len; denotes that varaible len is int(integer) data type.

char int; here int is a keyword cannot be used a variable name.

int long; here long is a keyword cannot be used a variable name.

float double; here double is a keyword cannot be used a variable name.

So, the answer is int len;(Option A).

30. Which of the following operations are INCORRECT?

A. int i = 35; i = i%5;

B. short int j = 255; j = j;

C. long int k = 365L; k = k;

Page 30: EXPRESSIONS - Google Groups

DURGA SOFTAWARE SOLUTIONS

CRT-C Language

DURGA SOFTWARE SOLUTIONS, 23/3RT, 2nd Floor. Opp: Reebok Shoe Room, Near Andhra Bank S.R Nagar, Hyderabad. Cell: 9246212143, Ph: 040-64512786 Page 30

D. float a = 4.14; a = a%3;

Answer: Option D

Explanation:

float a =4.14; a = a%3; gives "Illegal use of floating point" error.

The modulus (%) operator can only be used on integer types. We have to use fmod() function

present in math.h for floating values.

31. Which of the following correctly represents a double constant?

A. 6.68 B. 6.68L

C. 6.68f D. 6.68LF

Answer: Option A

Explanation:

6.68 is double.

6.68L is long double constant.

6.68f is float constant.

6.68LF is not allowed in c.

32. Which of the structure is incorrcet?

1 :

struct aa

{

int a=10;

float b=3.14f;

};

2 :

struct aa

{

int a;

float b;

struct aa var;

};

3 :

struct aa

{

int a;

float b;

struct aa *var;

Page 31: EXPRESSIONS - Google Groups

DURGA SOFTAWARE SOLUTIONS

CRT-C Language

DURGA SOFTWARE SOLUTIONS, 23/3RT, 2nd Floor. Opp: Reebok Shoe Room, Near Andhra Bank S.R Nagar, Hyderabad. Cell: 9246212143, Ph: 040-64512786 Page 31

};

A. 1 B. 2

C. 3 D. None of the above

Answer: Option D

Explanation:

1. In 1st structure there is a compilation error, we cannot assign values in structures for

structure members so 1st structure is invalid

2. Structure cannot conation variable of same type so 2nd

structure is invalid.

33. which of the following are correct?

1 : typedef long a;

extern int a c;

2 : typedef long a;

extern a int c;

3 : typedef long a;

extern a c;

A. 1 correct B. 2 correct

C. 3 correct D. 1, 2, 3 are correct

Answer: Option C

Explanation:

typedef long a;

extern int a c; while compiling this statement becomes extern int long c;. This will result in to

"Declaration syntax error".

typedef long a;

extern a int c; while compiling this statement becomes extern long int c;. This will result in to

"Too many types in declaration error".

typedef long a;

extern a c; while compiling this statement becomes extern long c;. This is a valid c declaration

statement. It says variable c is long data type and defined in some other file or module.

So, Option C is the correct answer.

34. A long double can be used if range of a double is not enough to accommodate a real number.

Page 32: EXPRESSIONS - Google Groups

DURGA SOFTAWARE SOLUTIONS

CRT-C Language

DURGA SOFTWARE SOLUTIONS, 23/3RT, 2nd Floor. Opp: Reebok Shoe Room, Near Andhra Bank S.R Nagar, Hyderabad. Cell: 9246212143, Ph: 040-64512786 Page 32

A. False B. True

Answer: Option B

Explanation:

True, we can use long double; if double range is not enough.

double = 8 bytes.

long double = 10 bytes.

35. A float is 4 bytes wide, whereas a double is 8 bytes wide. long double is 10 byte wide

A. True B. False

Answer: Option A

Explanation:

True,

float = 4 bytes.

double = 8 bytes.

long double=10 bytes .

36. If the definition of the external variable occurs in the source file before its use in a particular

function, then there is no need for an extern declaration in the function.

A. True B. False

Answer: Option A

Explanation:

True, When a function is declared inside the source file, that function(local function) get a

priority than the extern function. So there is no need to declare a function as extern inside the

same source file.

37. Size of short integer and long integer can be verified using the sizeof() operator.

A. True B. False

Page 33: EXPRESSIONS - Google Groups

DURGA SOFTAWARE SOLUTIONS

CRT-C Language

DURGA SOFTWARE SOLUTIONS, 23/3RT, 2nd Floor. Opp: Reebok Shoe Room, Near Andhra Bank S.R Nagar, Hyderabad. Cell: 9246212143, Ph: 040-64512786 Page 33

Answer: Option A

Explanation:

True, we can find the size of short integer and long integer using the sizeof() operator.

Example:

#include<stdio.h>

int main()

{

printf("short int is %d bytes.,\nlong int is %d bytes.",

sizeof(short),sizeof(long));

return 0;

}

Output:

short int is 2 bytes.

long int is 4 bytes.

38. Range of double is -1.7e-308 to 1.7e+308

A. True B. False

Answer: Option A

Explanation:

False, The range of double is -1.7e-308 to 1.7e+308.

39. Size of short integer and long integer would vary from one platform to another.

A. True B. False

Answer: Option A

Explanation:

True, Depending on the operating system/compiler/system architecture you are working on, the

range of data types can vary.

40. Range of float id -2.25e-38 to 2.25e+38

A. True B. False

Page 34: EXPRESSIONS - Google Groups

DURGA SOFTAWARE SOLUTIONS

CRT-C Language

DURGA SOFTWARE SOLUTIONS, 23/3RT, 2nd Floor. Opp: Reebok Shoe Room, Near Andhra Bank S.R Nagar, Hyderabad. Cell: 9246212143, Ph: 040-64512786 Page 34

Answer: Option B

Explanation:

False, The range of float is -3.4e-38 to 3.4e+38.

41. Is there any difference int the following declarations?

int myfun(int a[]);

int myfun(a[20]);

A. Yes B. No

Answer: Option A

Explanation:

Yes, we have to specify the data type of the parameter when declaring a function.

42. Suppose a program is divided into three files f1, f2 and f3, and a variable is defined in the file

f1 but used in files f2 and f3. In such a case would we need the extern declaration for the

variables in the files f2 and f3?

A. Yes B. No

Answer: Option A

Explanation:

Yes, Consider,

variable f1 in FILE1.C

variable f2 in FILE2.C

variable f3 in FILE3.C

If we need to use the variable f1 in the files FILE2.C and FILE3.C

We have to declare the variable f1 as extern int f1; in the files FILE2.C and FILE3.C.

43. Global variable are available to all functions. Does there exist a mechanism by way of which

it available to some and not to others.

A. Yes B. No

Answer: Option B

Page 35: EXPRESSIONS - Google Groups

DURGA SOFTAWARE SOLUTIONS

CRT-C Language

DURGA SOFTWARE SOLUTIONS, 23/3RT, 2nd Floor. Opp: Reebok Shoe Room, Near Andhra Bank S.R Nagar, Hyderabad. Cell: 9246212143, Ph: 040-64512786 Page 35

Explanation:

The only way this can be achieved is to define the variable locally in main() instead of defining it

globally and then passing it to the functions which need it.

44. Is it true that a global variable may have several declarations, but only one definition?

A. Yes B. No

Answer: Option A

Explanation:

Yes, In all the global variable declarations, you need to use the keyword extern.

45. Is it true that a function may have several declarations, but only one definition?

A. Yes B. No

Answer: Option A

Explanation:

Yes, but the function declarations must be identical.

Example:

#include<stdio.h>

void Disp ();

void Disp();

void Disp();

void Disp()

{

printf("Weclome to Durga Exams..!");

}

int main()

{

Disp();

return 0;

}

//Output:

Weclome to Durga Exams..!

Page 36: EXPRESSIONS - Google Groups

DURGA SOFTAWARE SOLUTIONS

CRT-C Language

DURGA SOFTWARE SOLUTIONS, 23/3RT, 2nd Floor. Opp: Reebok Shoe Room, Near Andhra Bank S.R Nagar, Hyderabad. Cell: 9246212143, Ph: 040-64512786 Page 36

Control Instructions

1.How many times "Durga Exams" is get printed?

#include<stdio.h>

int main()

{

int x;

for(x=-1; x<=10; x++)

{

if(x < 5)

continue;

else

break;

printf("Durga Exams ");

}

return 0;

}

A. Infinite times B. 11 times

C. 0 times D. 10 times

Answer: Option C

Explanation:

From x=-1 to 4 if condition present in for loop is satisfied so continue statement gets executed

as result it will go to the start of the loop. When x value is 5(x=5) then the if condition fails and

else body is executed so break is executed and control will come out of the loop so there will be

no output

2.void main()

{

float me = 1.1;

double you = 1.1;

if(me==you)

printf("I love U");

else

printf("I hate U");

}

A.I Love U B. I hate U C. no output D.none of the above

Answer:

Page 37: EXPRESSIONS - Google Groups

DURGA SOFTAWARE SOLUTIONS

CRT-C Language

DURGA SOFTWARE SOLUTIONS, 23/3RT, 2nd Floor. Opp: Reebok Shoe Room, Near Andhra Bank S.R Nagar, Hyderabad. Cell: 9246212143, Ph: 040-64512786 Page 37

I hate U

Explanation:

For floating point numbers (float, double, long double) the values cannot be

predicted exactly. Depending on the number of bytes, the precession with of the value

represented varies. Float takes 4 bytes and long double takes 10 bytes. So float stores 0.9

with less precision than long double.

Rule of Thumb:

Never compare or at-least be cautious when using floating point numbers with

relational operators (== , >, <, <=, >=,!= ) .

3. How many times the while loop will get executed if a short int is 2 byte wide?

#include<stdio.h>

int main()

{

int j=1;

while(j <= 256)

{

printf("%c %d\n", j, j);

j++;

}

return 0;

}

A. Infinite times B. 255 times

C. 256 times D. 254 times

Answer: Option C

Explanation:

The while(j <= 256) loop will get executed 256 times. The size short int(2 byte wide) does not

affect the while() loop.

3. Which of the following is not logical operator?

A. & B. &&

C. || D. !

Answer: Option A

Explanation:

Page 38: EXPRESSIONS - Google Groups

DURGA SOFTAWARE SOLUTIONS

CRT-C Language

DURGA SOFTWARE SOLUTIONS, 23/3RT, 2nd Floor. Opp: Reebok Shoe Room, Near Andhra Bank S.R Nagar, Hyderabad. Cell: 9246212143, Ph: 040-64512786 Page 38

Bitwise operators:

& is a Bitwise AND operator.

Logical operators:

&& is a Logical AND operator.

|| is a Logical OR operator.

! is a NOT operator.

So, '&' is not a Logical operator.

4.void main()

{

int i=3;

switch(i)

{

default:printf("zero");

case 1: printf("one");

break;

case 2:printf("two");

break;

case 3: printf("three");

break;

}

}

Answer :

Three

A.

Explanation :

The default case can be placed anywhere inside the loop. It is executed only

when all other cases doesn't match.

05.void main()

{

printf("%x",-1<<4);

}

Answer:

fff0

A. ffff B. fffo C. -1 D.

Explanation :

-1 is internally represented as all 1's. When left shifted four times the least

significant 4 bits are filled with 0's.The %x format specifier specifies that the integer value be

printed as a hexadecimal value.

12. main()

Page 39: EXPRESSIONS - Google Groups

DURGA SOFTAWARE SOLUTIONS

CRT-C Language

DURGA SOFTWARE SOLUTIONS, 23/3RT, 2nd Floor. Opp: Reebok Shoe Room, Near Andhra Bank S.R Nagar, Hyderabad. Cell: 9246212143, Ph: 040-64512786 Page 39

{

int c=- -2;

printf("c=%d",c);

}

Answer:

c=2;

A. -2 B. 2 C. 0 D. Error

Explanation:

Here unary minus (or negation) operator is used twice. Same maths rules

applies, ie. minus * minus= plus.

Note:

However you cannot give like --2. Because -- operator can only be applied to

variables as a decrement operator (eg., i--). 2 is a constant and not a variable.

06.void main()

{

int i=10;

i=!i>14;

Printf ("i=%d",i);

}

Answer:

i=0

Explanation:

A. 10 B. 1 C. 0 D. 14

In the expression !i>14 , NOT (!) operator has more precedence than ā€ž >ā€Ÿ

symbol. ! is a unary logical operator. !i (!10) is 0 (not of true is false). 0>14 is false (zero).

07.. Which is the correct order of mathematical operators ?

A. Addition, Subtraction, Multiplication, Division

B. Division, Multiplication, Addition, Subtraction

C. Multiplication, Addition, Division, Subtraction

D. Addition, Division, Modulus, Subtraction

Answer: Option B

Explanation:

The priority is decreased from top to bottom and same in the same line

/ * %

+ -

8. Which of the following cannot be checked in a switch-case statement?

Page 40: EXPRESSIONS - Google Groups

DURGA SOFTAWARE SOLUTIONS

CRT-C Language

DURGA SOFTWARE SOLUTIONS, 23/3RT, 2nd Floor. Opp: Reebok Shoe Room, Near Andhra Bank S.R Nagar, Hyderabad. Cell: 9246212143, Ph: 040-64512786 Page 40

A. Character B. Integer

C. Float D. enum

Answer: Option C

Explanation:

The switch/case statement in the c language is defined by the language specification to use an int

value, so you cannot use a float value.

char & enum internally considered as int so they can be used in switch-case

09.void main()

{

printf("\nab");

printf("\bsi");

printf("\rha");

}

A.absiha B.hai C.garbage value D.Error

Answer:

hai

Explanation:

\n - newline

\b - backspace

\r ā€“ linefeed

10. void main()

{

int i=5;

printf("%d%d%d%d%d%d",i++,i--,++i,--i,i);

}

A. 5 5 5 5 5 B. 4 4 4 4 4 C. 4 5 5 4 5 D. 5 6 4 3 3

Answer:

45545

Explanation:

The arguments in a function call are pushed into the stack from left to right.

The evaluation is by popping out from the stack. and the evaluation is from right to left,

hence the result.

11. What will be the output of the program?

Page 41: EXPRESSIONS - Google Groups

DURGA SOFTAWARE SOLUTIONS

CRT-C Language

DURGA SOFTWARE SOLUTIONS, 23/3RT, 2nd Floor. Opp: Reebok Shoe Room, Near Andhra Bank S.R Nagar, Hyderabad. Cell: 9246212143, Ph: 040-64512786 Page 41

#include<stdio.h>

int main()

{

int i=0;

for(; i<=5; i++);

printf("%d,", i);

return 0;

}

A. 0, 1, 2, 3, 4, 5 B. 5

C. 1, 2, 3, 4 D. 6

Answer: Option D

Explanation:

Step 1: int i = 0; here variable i is an integer type and initialized to '0'.

Step 2: for(; i<=5; i++); variable i=0 is already assigned in previous step. The semi-colon at the

end of this for loop tells, "there is no more statement is inside the loop".

Loop 1: here i=0, the condition in for(; 0<=5; i++) loop satisfies and then i is increemented by

'1'(one)

Loop 2: here i=1, the condition in for(; 1<=5; i++) loop satisfies and then i is increemented by

'1'(one)

Loop 3: here i=2, the condition in for(; 2<=5; i++) loop satisfies and then i is increemented by

'1'(one)

Loop 4: here i=3, the condition in for(; 3<=5; i++) loop satisfies and then i is increemented by

'1'(one)

Loop 5: here i=4, the condition in for(; 4<=5; i++) loop satisfies and then i is increemented by

'1'(one)

Loop 6: here i=5, the condition in for(; 5<=5; i++) loop satisfies and then i is increemented by

'1'(one)

Loop 7: here i=6, the condition in for(; 6<=5; i++) loop fails and then i is not increemented.

Step 3: printf("%d,", i); here the value of i is 6. Hence the output is '6'.

12. void main()

{

int i=400,j=300;

printf("%d..%d");

}

A.garbage value garbage value B.400..300 C.0..0

D.Error

Answer:

400..300

Page 42: EXPRESSIONS - Google Groups

DURGA SOFTAWARE SOLUTIONS

CRT-C Language

DURGA SOFTWARE SOLUTIONS, 23/3RT, 2nd Floor. Opp: Reebok Shoe Room, Near Andhra Bank S.R Nagar, Hyderabad. Cell: 9246212143, Ph: 040-64512786 Page 42

Explanation:

printf takes the values of the first two assignments of the program.

13. What will be the output of the program?

#include<stdio.h>

int main()

{

char str[]="C-program";

int a = 5;

printf(a >1?"Durga Exams\n":"%s\n", str);

return 0;

}

A. C-program B. Durga exams

C. Error D. None of above

Answer: Option B

Explanation:

Step 1: char str[]="C-program"; here variable str contains "C-program".

Step 2: int a = 5; here variable a contains "5".

Step 3: printf(a >1?"Ps\n":"%s\n", str); this statement can be written as

if(a > 1)

{

printf("Durga exams \n");

}

else

{

printf("%s\n", str);

}

Here we are checking a > 1 means 5 > 1. Hence this condition will be Satisfied . So it prints

Durga exams.

Hence the output is " Durga exams ".

14. Will the following code compile

void main()

{

int i=1;

Page 43: EXPRESSIONS - Google Groups

DURGA SOFTAWARE SOLUTIONS

CRT-C Language

DURGA SOFTWARE SOLUTIONS, 23/3RT, 2nd Floor. Opp: Reebok Shoe Room, Near Andhra Bank S.R Nagar, Hyderabad. Cell: 9246212143, Ph: 040-64512786 Page 43

while (i<=5)

{

printf("%d",i);

if (i>2)

goto here;

i++;

}

}

fun()

{

here:

printf("PP");

}

A. Yes B. No

Answer:

B.No

Compiler error: Undefined label 'here' in function main

Explanation:

Labels have functions scope, in other words The scope of the labels is limited to functions . The

label 'here' is available in function fun() Hence it is not visible in function main.

15. What will be the output of the program?

#include<stdio.h>

int main()

{

int a = 50, b = 10, c;

if(!a >= 400)

b = 30;

c = 200;

printf("b = %d c = %d\n", b, c);

return 0;

}

A. b = 30 c = 200 B. b = 10 c = garbage

C. b = 30 c = garbage D. b = 10 c = 200

Answer: Option D

Explanation:

Initially variables a = 50, b = 10 and c is not assigned.

Step 1: if(!a >= 400)

Step 2: if(!50 >= 400)

Step 3: if(0 >= 400)

Page 44: EXPRESSIONS - Google Groups

DURGA SOFTAWARE SOLUTIONS

CRT-C Language

DURGA SOFTWARE SOLUTIONS, 23/3RT, 2nd Floor. Opp: Reebok Shoe Room, Near Andhra Bank S.R Nagar, Hyderabad. Cell: 9246212143, Ph: 040-64512786 Page 44

Step 4: if(FALSE) Hence the if condition is failed.

Step 5: So, variable c is assigned to a value '200'.

Step 6: printf("b = %d c = %d\n", b, c); It prints value of b and c.

Hence the output is "b = 10 c = 200"

16. void main()

{

int i=5;

printf("%d",i++ + ++i);

}

Answer:

Output Cannot be predicted exactly.

Explanation:

Side effects are involved in the evaluation of i

17.Will the following code compile

void main()

{

int i=5;

printf("%d",i+++++i);

}

A. Yes B. No

Answer:

Compiler Error

Explanation:

The expression i+++++i is parsed as i ++ ++ + i which is an illegal

combination of operators.

18. #include<stdio.h>

main()

{

int i=1,j=2;

switch(i)

{

case 1: printf("GOOD");

break;

case j: printf("BAD");

break;

}

}

A. BAD B.GOOD C.GOODBAD D.error

Answer:

Compiler Error: Constant expression required in function main.

Page 45: EXPRESSIONS - Google Groups

DURGA SOFTAWARE SOLUTIONS

CRT-C Language

DURGA SOFTWARE SOLUTIONS, 23/3RT, 2nd Floor. Opp: Reebok Shoe Room, Near Andhra Bank S.R Nagar, Hyderabad. Cell: 9246212143, Ph: 040-64512786 Page 45

Explanation:

The case statement can have only constant expressions (this implies that we

cannot use variable names directly so an error).

Note:

Enumerated types can be used in case statements.

19. Will the following code compile

void main()

{

int i;

printf("%d",scanf("%d",&i)); // value 10 is given as input here

}

A. Yes B. No

Answer:

1

Explanation:

Scanf returns number of items successfully read and not 1/0. Here 10 is

given as input which should have been scanned successfully. So number of

items read is 1.

20. What will be the output of the program?

#include<stdio.h>

int main()

{

unsigned int i = 65535; /* Assume 2 byte integer*/

while(i++ >= 0)

printf("%d",i);

printf("\n");

return 0;

}

A. Infinite loop

B. 0 1 2 ... 65535

C. 0 1 2 ... 32767 - 32766 -32765 -1 0

D. No output

Answer: Option A

Explanation:

Here unsigned int size is 2 bytes. It varies from 0,1,2,3, ... to 65535.

Step 1:unsigned int i = 65535;

Page 46: EXPRESSIONS - Google Groups

DURGA SOFTAWARE SOLUTIONS

CRT-C Language

DURGA SOFTWARE SOLUTIONS, 23/3RT, 2nd Floor. Opp: Reebok Shoe Room, Near Andhra Bank S.R Nagar, Hyderabad. Cell: 9246212143, Ph: 040-64512786 Page 46

Step 2:

Loop 1:.

As the i is declared unsigned int the range of it is 0 to 65535 . so the range is always greater than

0 so it will fall in infinite loop.

21.void main()

{

int i=0;

for(;i++;printf("%d",i)) ;

printf("%d",i);

}

A. 0 B.1 C. infinite loop D.error

Answer:

1

Explanation:

before entering into the for loop the checking condition is "evaluated". Here it

evaluates to 0 (false) and comes out of the loop, and i is incremented (note

the semicolon after the for loop).

22. What will be the output of the program?

#include<stdio.h>

int main()

{

int x = 3;

float y = 3.0;

if(x == y)

printf("I love you");

else

printf("I hate you");

return 0;

}

A. I love you B. I hate you

C. Unpredictable D. No output

Answer: Option A

Explanation:

Step 1: int x = 3; here variable x is an integer type and initialized to '3'.

Step 2: float y = 3.0; here variable y is an float type and initialized to '3.0'

Step 3: if(x == y) here we are comparing if(3 == 3.0) hence this condition is satisfied.

Hence it prints "I love you".

Page 47: EXPRESSIONS - Google Groups

DURGA SOFTAWARE SOLUTIONS

CRT-C Language

DURGA SOFTWARE SOLUTIONS, 23/3RT, 2nd Floor. Opp: Reebok Shoe Room, Near Andhra Bank S.R Nagar, Hyderabad. Cell: 9246212143, Ph: 040-64512786 Page 47

23. What will be the output of the program?

#include<stdio.h>

int main()

{

char ch;

if(ch = printf(""))

printf("It matters\n");

else

printf("It doesn't matters\n");

return 0;

}

A. It matters B. It doesn't matters

C. matters D. No output

Answer: Option B

Explanation:

printf() returns the number of charecters printed on the console.

Step 1: if(ch = printf("")) here printf() does not print anything, so it returns '0'(zero).

Step 2: if(ch = 0) here variable ch has the value '0'(zero).

Step 3: if(0) Hence the if condition is not satisfied. So it prints the else statements.

Hence the output is "It doesn't matters".

Note: Compiler shows a warning "possibly incorrect assinment".

24.void main( )

{

char *q;

int j;

for (j=0; j<3; j++) scanf(ā€œ%sā€ ,(q+j));

for (j=0; j<3; j++) printf(ā€œ%cā€ ,*(q+j));

for (j=0; j<3; j++) printf(ā€œ%sā€ ,(q+j));

}

Explanation:

Here we have only one pointer to type char and since we take input in the

same pointer thus we keep writing over in the same location, each time

shifting the pointer value by 1. Suppose the inputs are MOUSE, TRACK and

VIRTUAL. Then for the first input suppose the pointer starts at location 100

then the input one is stored as

M O U S E \0

When the second input is given the pointer is incremented as j value

Page 48: EXPRESSIONS - Google Groups

DURGA SOFTAWARE SOLUTIONS

CRT-C Language

DURGA SOFTWARE SOLUTIONS, 23/3RT, 2nd Floor. Opp: Reebok Shoe Room, Near Andhra Bank S.R Nagar, Hyderabad. Cell: 9246212143, Ph: 040-64512786 Page 48

becomes 1, so the input is filled in memory starting from 101.

M T R A C K \0

The third input starts filling from the location 102

M T V I R T U A L \0

This is the final value stored .

The first printf prints the values at the position q, q+1 and q+2 = M T V

The second printf prints three strings starting from locations q, q+1, q+2

i.e MTVIRTUAL, TVIRTUAL and VIRTUAL.

25. What will be the output of the program?

#include<stdio.h>

int main()

{

float a = 0.7;

if(0.7 > a)

printf("Hi if\n");

else

printf("Hello else\n");

return 0;

}

A. Hi if B. Hello else

C. Hi if Hello else D. None of above

Answer & Explanation

Answer: Option A

Explanation:

float data type is double precision .double data type is a single precision so due to loss in

precision in the statement float f=0.7( internally it is stored as 0.699999)

if(0.7 > a) here a is a float variable and 0.7 is a double constant. The double constant 0.7 is

greater than the float variable a. Hence the if condition is satisfied and it prints 'Hi if'

26.Will the following code compile

void main()

{

int k=1;

printf("%d==1 is ""%s",k,k==1?"TRUE":"FALSE");

}

A. Yes B. No

Page 49: EXPRESSIONS - Google Groups

DURGA SOFTAWARE SOLUTIONS

CRT-C Language

DURGA SOFTWARE SOLUTIONS, 23/3RT, 2nd Floor. Opp: Reebok Shoe Room, Near Andhra Bank S.R Nagar, Hyderabad. Cell: 9246212143, Ph: 040-64512786 Page 49

Answer:

A. Yes

1==1 is TRUE

Explanation:

When two strings are placed together (or separated by white-space) they are

concatenated (this is called as "stringization" operation). So the string is as if

it is given as "%d==1 is %s". The conditional operator( ?: ) evaluates to

"TRUE".

27. The program is used to check whether the given year is leap or not

void main()

{

int y;

scanf("%d",&y); // input given is 2000

if( (y%4==0 && y%100 != 0) || y%100 == 0 )

printf("%d is a leap year");

else

printf("%d is not a leap year");

}

A. Yes B. No

Answer:

A.Yes

Explanation:

2000 is a leap yea

28. What will be the output of the program?

#include<stdio.h>

int main()

{

int a=0, b=1, c=3;

*((a) ? &b : &a) = a ? b: c;

printf("%d, %d, %d\n", a, b, c);

return 0;

}

A. 0, 1, 3 B. 1, 2, 3

C. 3, 1, 3 D. 1, 3, 1

Answer: Option C

Explanation:

Step 1: int a=0, b=1, c=3; here variable a, b, and c are declared as integer type and initialized to

0, 1, 3 respectively.

Page 50: EXPRESSIONS - Google Groups

DURGA SOFTAWARE SOLUTIONS

CRT-C Language

DURGA SOFTWARE SOLUTIONS, 23/3RT, 2nd Floor. Opp: Reebok Shoe Room, Near Andhra Bank S.R Nagar, Hyderabad. Cell: 9246212143, Ph: 040-64512786 Page 50

Step 2: *((a) ? &b : &a) = a ? b : c; The right side of the expression(a?b:c) becomes (0?1:3).

Hence it return the value '3'.

The left side of the expression *((a) ? &b : &a) becomes *((0) ? &b : &a). Hence this contains

the address of the variable a *(&a).

Step 3: *((a) ? &b : &a) = a ? b : c; Finally this statement becomes *(&a)=3. Hence the variable

a has the value '3'.

Step 4: printf("%d, %d, %d\n", a, b, c); It prints "3, 1, 3".

29. What will be the output of the program?

#include<stdio.h>

int main()

{

int i = 5;

while(i-- >= 0)

printf("%d,", i);

i = 5;

printf("\n");

while(i-- >= 0)

printf("%i,", i);

while(i-- >= 0)

printf("%d,", i);

return 0;

}

A.

4, 3, 2, 1, 0, -1

4, 3, 2, 1, 0, -1 B.

5, 4, 3, 2, 1, 0

5, 4, 3, 2, 1, 0

C. Error D.

5, 4, 3, 2, 1, 0

5, 4, 3, 2, 1, 0

5, 4, 3, 2, 1, 0

Answer: Option A

Explanation:

Step 1: Initially the value of variable i is '5'.

Loop 1: while(i-- >= 0) here i = 5, this statement becomes while(5-- >= 0) Hence the while

condition is satisfied and it prints '4'. (variable 'i' is decremented by '1'(one) in previous while

condition)

Loop 2: while(i-- >= 0) here i = 4, this statement becomes while(4-- >= 0) Hence the while

Page 51: EXPRESSIONS - Google Groups

DURGA SOFTAWARE SOLUTIONS

CRT-C Language

DURGA SOFTWARE SOLUTIONS, 23/3RT, 2nd Floor. Opp: Reebok Shoe Room, Near Andhra Bank S.R Nagar, Hyderabad. Cell: 9246212143, Ph: 040-64512786 Page 51

condition is satisfied and it prints '3'. (variable 'i' is decremented by '1'(one) in previous while

condition)

Loop 3: while(i-- >= 0) here i = 3, this statement becomes while(3-- >= 0) Hence the while

condition is satisfied and it prints '2'. (variable 'i' is decremented by '1'(one) in previous while

condition)

Loop 4: while(i-- >= 0) here i = 2, this statement becomes while(2-- >= 0) Hence the while

condition is satisfied and it prints '1'. (variable 'i' is decremented by '1'(one) in previous while

condition)

Loop 5: while(i-- >= 0) here i = 1, this statement becomes while(1-- >= 0) Hence the while

condition is satisfied and it prints '0'. (variable 'i' is decremented by '1'(one) in previous while

condition)

Loop 6: while(i-- >= 0) here i = 0, this statement becomes while(0-- >= 0) Hence the while

condition is satisfied and it prints '-1'. (variable 'i' is decremented by '1'(one) in previous while

condition)

Loop 7: while(i-- >= 0) here i = -1, this statement becomes while(-1-- >= 0) Hence the while

condition is not satisfied and loop exits.

The output of first while loop is 4,3,2,1,0,-1

Step 2: Then the value of variable i is initialized to '5' Then it prints a new line character(\n).

See the above Loop 1 to Loop 7 .

The output of second while loop is 4,3,2,1,0,-1

Step 3: The third while loop, while(i-- >= 0) here i = -1(because the variable 'i' is decremented to

'-1' by previous while loop and it never initialized.). This statement becomes while(-1-- >= 0)

Hence the while condition is not satisfied and loop exits.

Hence the output of the program is

4,3,2,1,0,-1

4,3,2,1,0,-1

30.Will the following code compilemain()

{

int i=-1;

-i;

printf("i = %d, -i = %d \n",i,-i);

}

A. Yes B. No

Answer:

Yes

i = -1, -i = 1

Explanation:

-i is executed and this execution doesn't affect the value of i. In printf first you

just print the value of i. After that the value of the expression -i = -(-1) is

printed.

Page 52: EXPRESSIONS - Google Groups

DURGA SOFTAWARE SOLUTIONS

CRT-C Language

DURGA SOFTWARE SOLUTIONS, 23/3RT, 2nd Floor. Opp: Reebok Shoe Room, Near Andhra Bank S.R Nagar, Hyderabad. Cell: 9246212143, Ph: 040-64512786 Page 52

31.Will the following code compile

#include<stdio.h>

void main()

{

const int i=4;

float j;

j = ++i;

printf("%d %f", i,++j);

}

A. Yes B. No

Answer:

B. No

Compiler error

Explanation:

i is a constant. you cannot change the value of constant

32. Will the following code compile

void main()

{

int i=-1;

-i;

printf("i = %d, -i = %d \n",i,-i);

}

B. Yes B. No

Answer:

Yes

i = -1, -i = 1

Explanation:

-i is executed and this execution doesn't affect the value of i. In printf first you

just print the value of i. After that the value of the expression -i = -(-1) is

printed.

33.Will the following code compile

#include<stdio.h>

void main()

{

const int i=4;

float j;

j = ++i;

printf("%d %f", i,++j);

}

Page 53: EXPRESSIONS - Google Groups

DURGA SOFTAWARE SOLUTIONS

CRT-C Language

DURGA SOFTWARE SOLUTIONS, 23/3RT, 2nd Floor. Opp: Reebok Shoe Room, Near Andhra Bank S.R Nagar, Hyderabad. Cell: 9246212143, Ph: 040-64512786 Page 53

B. Yes B. No

Answer:

B. No

Compiler error

Explanation:

i is a constant. you cannot change the value of constant

34. What will be the output of the program?

#include<stdio.h>

int main()

{

int i=3;

switch(i)

{

case 1:

printf("Hello\n");

case 2:

printf("Hi\n");

case 3:

printf("Bye\n");

default:

continue;

}

return 0;

}

A. Error: Misplaced continue B. Bye

C. No output D. Hello Hi

Answer & Explanation

Answer: Option A

Explanation:

The keyword continue cannot be used in switch case. It must be used in for or while or do while

loop. If there is any looping statement in switch case then we can use continue.

35. What will be the output of the program?

#include<stdio.h>

int main()

{

int x = 1, y = 2;

Page 54: EXPRESSIONS - Google Groups

DURGA SOFTAWARE SOLUTIONS

CRT-C Language

DURGA SOFTWARE SOLUTIONS, 23/3RT, 2nd Floor. Opp: Reebok Shoe Room, Near Andhra Bank S.R Nagar, Hyderabad. Cell: 9246212143, Ph: 040-64512786 Page 54

if(!(!x) && x)

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

else

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

return 0;

}

A. y =20 B. x = 0

C. x = 1 D. x = 1

Answer & Explanation

Answer: Option C

Explanation:

The logical not operator takes expression and evaluates to true if the expression is false and

evaluates to false if the expression is true. In other words it reverses the value of the expression.

Step 1: if(!(!x) && x)

Step 2: if(!(!1) && 1)

Step 3: if(!(0) && 1)

Step 3: if(1 && 1)

Step 4: if(TRUE) here the if condition is satisfied. Hence it prints x = 1.

36. void main()

{

int i=5,j=6,z;

printf("%d",i+++j);

}

Answer:

11

Explanation:

the expression i+++j is treated as (i++ + j)

37. What will be the output of the program?

#include<stdio.h>

int main()

{

int i=4;

switch(i)

{

default:

printf("This is default\n");

case 1:

printf("This is case 1\n");

Page 55: EXPRESSIONS - Google Groups

DURGA SOFTAWARE SOLUTIONS

CRT-C Language

DURGA SOFTWARE SOLUTIONS, 23/3RT, 2nd Floor. Opp: Reebok Shoe Room, Near Andhra Bank S.R Nagar, Hyderabad. Cell: 9246212143, Ph: 040-64512786 Page 55

case 2:

printf("This is case 2\n");

break;

case 3:

printf("This is case 3\n");

}

return 0;

}

A.

This is default

This is case 1

This is case 2

B.

This is case 3

This is default

C.

This is case 1

This is case 3 D. This is default

Answer & Explanation

Answer: Option A

Explanation:

In the very begining of switch-case statement default statement is encountered. So, it prints "This

is default".

In default statement there is no break; statement is included. So it prints the case 1 statements.

"This is case 1". In case 1 statement there is no break; statement is included so it prints ā€œThis is

case 2ā€

Then the break; statement is encountered. Hence the program exits from the switch-case block.

38. void main()

{

int i =0;j=0;

if(i && j++)

printf("%d..%d",i++,j);

printf("%d..%d,i,j);

}

A. 0..0 B. 0..1 C. 1..1 D.error

Answer:

A. 0..0

Explanation:

Page 56: EXPRESSIONS - Google Groups

DURGA SOFTAWARE SOLUTIONS

CRT-C Language

DURGA SOFTWARE SOLUTIONS, 23/3RT, 2nd Floor. Opp: Reebok Shoe Room, Near Andhra Bank S.R Nagar, Hyderabad. Cell: 9246212143, Ph: 040-64512786 Page 56

The value of i is 0. Since this information is enough to determine the truth

value of the boolean expression. So the statement following the if statement

is not executed. The values of i and j remain unchanged and get printed.

39.

void main(){

int a= 0;int b = 20;char x =1;char y =10;

if(a,b,x,y)

printf("hello");

}

A.hello B.nooutput C.error D.none of the above

Answer:

hello

Explanation:

The comma operator has associativity from left to right. Only the rightmost

value is returned and the other values are evaluated and ignored. Thus the

value of last variable y is returned to check in if. Since it is a non zero value if becomes true so,

"hello" will be printed.

40. What will be the output of the program?

#include<stdio.h>

int main()

{

int i = 1;

switch(i)

{

printf("Hello\n");

case 1:

printf("Hi\n");

break;

case 2:

printf("\nBye\n");

break;

}

return 0;

}

A.

Hello

Hi B.

Hello

Bye

C. Hi D. Bye

Answer & Explanation

Answer: Option C

Page 57: EXPRESSIONS - Google Groups

DURGA SOFTAWARE SOLUTIONS

CRT-C Language

DURGA SOFTWARE SOLUTIONS, 23/3RT, 2nd Floor. Opp: Reebok Shoe Room, Near Andhra Bank S.R Nagar, Hyderabad. Cell: 9246212143, Ph: 040-64512786 Page 57

Explanation:

switch(i) has the variable i it has the value '1'(one).

Then case 1: statements got executed. so, it prints "Hi". The break; statement make the program

to be exited from switch-case statement.

switch-case do not execute any statements outside these blocks case and default

Hence the output is "Hi".

41. Will the following code compile

void main()

{

int i=-1;

+i;

printf("i = %d, +i = %d \n",i,+i);

}

A. Yes B. No

Answer:

Yes

Output: i = -1, +i = -1

42. What will be the output of the program?

#include<stdio.h>

int main()

{

char j=1;

while(j < 5)

{

printf("%d, ", j);

j = j+1;

}

printf("\n");

return 0;

}

A. 1 2 3 ... 127

B. 1 2 3 ... 255

C. 1 2 3 ... 127 128 0 1 2 3 ... infinite times

D. 1, 2, 3, 4

Answer: option D

Page 58: EXPRESSIONS - Google Groups

DURGA SOFTAWARE SOLUTIONS

CRT-C Language

DURGA SOFTWARE SOLUTIONS, 23/3RT, 2nd Floor. Opp: Reebok Shoe Room, Near Andhra Bank S.R Nagar, Hyderabad. Cell: 9246212143, Ph: 040-64512786 Page 58

Explanation

Internally char is treated as int

while(1<5) it is true enters the loop

prints j values as 1

j value is incremented by 1 i.e now j value is 2

while(2<5) it is true enters the loop

prints j values as 2

j value is incremented by 1 i.e now j value is 3

while(3<5) it is true enters the loop

prints j values as 3

j value is incremented by 1 i.e now j value is 4

while(4<5) it is true enters the loop

prints j values as 4

j value is incremented by 1 i.e now j value is 5

while(5<5) it is false exits from loop

43. What will be the output of the program?

#include<stdio.h>

int main()

{

int x, y, z;

x=y=z=1;

z = ++x || ++y && ++z;

printf("x=%d, y=%d, z=%d\n", x, y, z);

return 0;

}

A. x=2, y=1, z=1 B. x=2, y=2, z=1

C. x=2, y=2, z=2 D. x=1, y=2, z=1

Answer & Explanation

Answer: Option A

Explanation:

Step 1: x=y=z=1; here the variables x ,y, z are initialized to value '1'.

Step 2: z = ++x || ++y && ++z; becomes z = ( (++x) || (++y && ++z) ). Here ++x becomes 2. So

there is no need to check the other side because ||(Logical OR) condition is satisfied.(z = (2 || ++y

&& ++z)). There is no need to process ++y && ++z. Hence it returns '1'. So the value of variable

z is '1'

Page 59: EXPRESSIONS - Google Groups

DURGA SOFTAWARE SOLUTIONS

CRT-C Language

DURGA SOFTWARE SOLUTIONS, 23/3RT, 2nd Floor. Opp: Reebok Shoe Room, Near Andhra Bank S.R Nagar, Hyderabad. Cell: 9246212143, Ph: 040-64512786 Page 59

Step 3: printf("x=%d, y=%d, z=%d\n", x, y, z); It prints "x=2, y=1, z=1". here x is increemented

in previous step. y and z are not increemented.

44. Point out the error, if any in the for loop.

#include<stdio.h>

int main()

{

int i=1;

for(;;)

{

printf("%d\n", i++);

if(i>10)

break;

}

return 0;

}

A. There should be a condition in the for loop

B. The two semicolons should be dropped

C. The for loop should be replaced with while loop.

D. No error

Answer & Explanation

Answer: Option D

Explanation:

Step 1: for(;;) this statement will genereate infinite loop.

Step 2: printf("%d\n", i++); this statement will print the value of variable i and increement i by

1(one).

Step 3: if(i>10) here, if the variable i value is greater than 10, then the for loop breaks.

Hence the output of the program is

1

2

3

4

5

6

7

8

9

10

45.. #include<stdio.h>

Page 60: EXPRESSIONS - Google Groups

DURGA SOFTAWARE SOLUTIONS

CRT-C Language

DURGA SOFTWARE SOLUTIONS, 23/3RT, 2nd Floor. Opp: Reebok Shoe Room, Near Andhra Bank S.R Nagar, Hyderabad. Cell: 9246212143, Ph: 040-64512786 Page 60

int main()

{

int a = 1000;

switch(a)

{

}

printf("This is c program.");

return 0;

}

A. Error: No case statement specified

B. Error: No default specified

C. No Error

D. Error: infinite loop occurs

Answer & Explanation

Answer: Option C

Explanation:

There can exists a switch statement, which has no case.

46. Point out the error, if any in the program.

#include<stdio.h>

void main()

{

int i ;

i=1;

switch(i)

{

printf("This is c program.");

case 1:

printf("Case1");

break;

case 2:

printf("Case2");

break;

}

}

A. Error: No default specified

B. Error: Invalid printf statement after switch statement

C. No Error and prints "Case1"

D. None of above

Answer: Option C

Page 61: EXPRESSIONS - Google Groups

DURGA SOFTAWARE SOLUTIONS

CRT-C Language

DURGA SOFTWARE SOLUTIONS, 23/3RT, 2nd Floor. Opp: Reebok Shoe Room, Near Andhra Bank S.R Nagar, Hyderabad. Cell: 9246212143, Ph: 040-64512786 Page 61

Explanation:

switch(i) becomes switch(1), then the case 1: block is get executed. Hence it prints "Case1".

printf("This is c program."); is ignored by the compiler.

Hence there is no error and prints "Case1".

47. Point out the error, if any in the while loop.

#include<stdio.h>

int main()

{

int i=0;

while()

{

printf("%d\n", i++);

if(i>10)

break;

}

return 0;

}

A. There should be a condition in the while loop

B. There should be at least a semicolon in the while

C. The while loop should be replaced with for loop.

D. No error

Answer & Explanation

Answer: Option A

Explanation:

As per the syntax there should be some condition in the while. Here we are missing the condition

so we get a compilation error saying: "Expression syntax" error.

48. Which of the following errors would be reported by the compiler on compiling the program

given below?

#include<stdio.h>

int main()

{

int a = 4;

switch(a)

{

case 1:

Page 62: EXPRESSIONS - Google Groups

DURGA SOFTAWARE SOLUTIONS

CRT-C Language

DURGA SOFTWARE SOLUTIONS, 23/3RT, 2nd Floor. Opp: Reebok Shoe Room, Near Andhra Bank S.R Nagar, Hyderabad. Cell: 9246212143, Ph: 040-64512786 Page 62

printf("First");

case 2:

printf("Second");

case 3 + 1:

printf("Third");

case 4:

printf("Final");

break;

}

return 0;

}

A. There is no break statement in each case.

B. Expression as in case 3 + 1 is not allowed.

C. Duplicate case case 4:

D. No error will be reported.

Answer & Explanation

Answer: Option C

Explanation:

In switch there cannot have two or more cases with same constant lable. So, case 3 + 1: and case

4: have the same constant value 4.so we get duplicate case compilation error

49. Point out the error, if any in the program.

#include<stdio.h>

int main()

{

int j = 100;

switch(j)

{

case 10:

printf("Case 1");

case 20:

printf("Case 2");

break;

Page 63: EXPRESSIONS - Google Groups

DURGA SOFTAWARE SOLUTIONS

CRT-C Language

DURGA SOFTWARE SOLUTIONS, 23/3RT, 2nd Floor. Opp: Reebok Shoe Room, Near Andhra Bank S.R Nagar, Hyderabad. Cell: 9246212143, Ph: 040-64512786 Page 63

case j:

printf("Case j");

break;

}

return 0;

}

A. Error: No default value is specified

B. Error: Constant expression required at line case j:

C. Error: There is no break statement in each case.

D. No error will be reported.

Answer: Option B

Explanation:

The compiler will report the error "Constant expression required" in the line case j: . Because,

variable names cannot be used with case statements.

The case statements will accept only constant expression.

50. Point out the error, if any in the program.

#include<stdio.h>

int main()

{

int i = 10;

switch(i)

{

case 1:

printf("Case10");

break;

case 1*2+4:

printf("Case2");

break;

}

return 0;

}

A. Error: in case 1*2+4 statement

B. Error: No default specified

C. Error: in switch statement

D. No Error

Answer: Option D

Page 64: EXPRESSIONS - Google Groups

DURGA SOFTAWARE SOLUTIONS

CRT-C Language

DURGA SOFTWARE SOLUTIONS, 23/3RT, 2nd Floor. Opp: Reebok Shoe Room, Near Andhra Bank S.R Nagar, Hyderabad. Cell: 9246212143, Ph: 040-64512786 Page 64

Explanation:

Constant expression are accepted in switch

It prints "Case10"

51. Point out the error, if any in the while loop.

#include<stdio.h>

int main()

{

void fun();

int i = 1;

while(i <= 5)

{

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

if(i>2)

goto here;

}

return 0;

}

void fun()

{

here:

printf("It works");

}

A. No Error: prints "It works"

B. Error: fun() cannot be accessed

C. Error: goto cannot takeover control to other function

D. No error

Answer: Option C

Explanation:

goto is unconditional construct which transfer the control form one position to another position

unconditionally within the function. A label is used as the target of a goto statement, and that

label must be within the same function as the goto statement.

There are two type of jumps a) forward jump b) backward jump

Point out the error, if any in the program.

52. #include<stdio.h>

int main()

Page 65: EXPRESSIONS - Google Groups

DURGA SOFTAWARE SOLUTIONS

CRT-C Language

DURGA SOFTWARE SOLUTIONS, 23/3RT, 2nd Floor. Opp: Reebok Shoe Room, Near Andhra Bank S.R Nagar, Hyderabad. Cell: 9246212143, Ph: 040-64512786 Page 65

{

int a = 10, b;

a >=5 ? b=100: b=200;

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

return 0;

}

A. 100 B. 200

C. Error: L value required for b D. Garbage value

Answer & Explanation

Answer: Option C

Explanation:

The error is at b=100 and at b=200 to remove errors write has (b=100) and (b=200)

If you replace above statement with this a>=5?(b=100)b=200);

The output is :100

53. Which of the following statements are correct about the below program?

#include<stdio.h>

int main()

{

int i = 10, j = 20;

if(i = 5) && if(j = 10)

printf("Have a nice day");

return 0;

}

A. Output: Have a nice day

B. No output

C. Error: Expression syntax

D. Error: Undeclared identifier if

Answer & Explanation

Answer: Option C

Explanation:

"Expression syntax" error occur in this line if(i = 5) && if(j = 10).

It should be like if((i == 5) && (j == 10)).

Page 66: EXPRESSIONS - Google Groups

DURGA SOFTAWARE SOLUTIONS

CRT-C Language

DURGA SOFTWARE SOLUTIONS, 23/3RT, 2nd Floor. Opp: Reebok Shoe Room, Near Andhra Bank S.R Nagar, Hyderabad. Cell: 9246212143, Ph: 040-64512786 Page 66

54. Which of the following statements are correct about the below program?

#include<stdio.h>

int main()

{

int i = 10, j = 15;

if(i % 2 = j % 3)

printf("IndiaBIX\n");

return 0;

}

A. Error: Expression syntax B. Error: Lvalue required

C. Error: Rvalue required D. The Code runs successfully

Answer: Option B

Explanation:

if(i % 2 = j % 3) This statement generates "LValue required error". There is no variable on the

left side of the expression to assign (j % 3).

55. Point out the correct statements are correct about the program below?

#include<stdio.h>

int main()

{

char x;

while(x=0;x<=255;x++)

printf("ASCII value of %d character %c\n", x, x);

return 0;

}

A. The code generates an infinite loop

B. The code prints all ASCII values and its characters

C. Error: x undeclared identifier

D. Error: while statement missing

Answer & Explanation

Answer: Option D

Explanation:

Here while() statement syntax error. replace while with for.

56. Which of the following statements are correct about the below program?

Page 67: EXPRESSIONS - Google Groups

DURGA SOFTAWARE SOLUTIONS

CRT-C Language

DURGA SOFTWARE SOLUTIONS, 23/3RT, 2nd Floor. Opp: Reebok Shoe Room, Near Andhra Bank S.R Nagar, Hyderabad. Cell: 9246212143, Ph: 040-64512786 Page 67

#include<stdio.h>

int main()

{

int i = 0;

i++;

if(i++ <= 5)

{

printf("Durga exams\n");

exit();

main();

}

return 0;

}

A. The program prints ' Durga exams ' 5 times

B. The program prints ' Durga exams ' one time

C. The call to main() after exit() doesn't materialize.

D. The compiler reports an error since main() cannot call itself.

Answer & Explanation

Answer: Option B

Explanation:

Step 1: int i = 0; here variable i is declared as an integer type and initialized to '0'(zero).

Step 2: i++; here variable i is increemented by 1(one). Hence, i = 1

Step 3: if(i++ <= 5) becomes if(1 <= 5) here we are checking '1' is less than or equal to '5'.

Hence the if condition is satisfied.

Step 4: printf("Durga exams \n"); It prints " Durga exams "

Step 5: exit(); terminates the program execution.

Hence the output is " Durga exams ".

57. Which of the following statements are correct about the below C-program?

#include<stdio.h>

int main()

{

int x = 10, y = 100%90, i;

for(i=1; i<10; i++)

if(x != y);

printf("x = %d y = %d\n", x, y);

return 0;

}

1 : The printf() function is called 10 times.

2 : The program will produce the output x = 10 y = 10

Page 68: EXPRESSIONS - Google Groups

DURGA SOFTAWARE SOLUTIONS

CRT-C Language

DURGA SOFTWARE SOLUTIONS, 23/3RT, 2nd Floor. Opp: Reebok Shoe Room, Near Andhra Bank S.R Nagar, Hyderabad. Cell: 9246212143, Ph: 040-64512786 Page 68

3 : The ; after the if(x!=y) will NOT produce an error.

4 : The program will not produce output.

A. 1 B. 2, 3

C. 3, 4 D. 4

Answer: Option B

Explanation:

if(x!=y); is treated as for body, that will be executed 9 times. For the 10th

time the condition fails

and it will produce output as x=10 y=10

58. The way the break is used to take control out of switch can continue to take control of the

beginning of the switch?

A. True B. False

Answer: Option B

Explanation:

continue can work only with loops and not with switch

59. Can we use a switch statement to switch on strings?

A. True B. False

Answer & Explanation

Answer: Option B

Explanation:

The cases in a switch must either have integer constants or constant expressions.

60.We want to test whether a value lies in the range 1 to 3 or 9 to 11. Can we do this using a

switch?

A. True B. False

Answer & Explanation

Answer: Option A

Page 69: EXPRESSIONS - Google Groups

DURGA SOFTAWARE SOLUTIONS

CRT-C Language

DURGA SOFTWARE SOLUTIONS, 23/3RT, 2nd Floor. Opp: Reebok Shoe Room, Near Andhra Bank S.R Nagar, Hyderabad. Cell: 9246212143, Ph: 040-64512786 Page 69

Explanation:

We can do this in following switch statement

switch(a)

{

case 1:

case 2:

case 3:

/* some statements */

break;

case 9:

case 10:

case 11:

/* some statements */

break;

}

Floating Point Concepts

1. What are the different types of real data type in C ?

A. float, double,long B. short int, double, long int,char

C. float, double, long double D. double, long int, float

Answer & Explanation

Answer: Option C

Explanation: The floating point data types are called real data types. Hence float, double, and long double are

real data types.

2. What will you do to treat the constant 3.14 as a long double?

A. use 3.14LD B. use 3.14L

C. use 3.14DL D. use 3.14LF

Answer & Explanation

Answer: Option B

Explanation:

Page 70: EXPRESSIONS - Google Groups

DURGA SOFTAWARE SOLUTIONS

CRT-C Language

DURGA SOFTWARE SOLUTIONS, 23/3RT, 2nd Floor. Opp: Reebok Shoe Room, Near Andhra Bank S.R Nagar, Hyderabad. Cell: 9246212143, Ph: 040-64512786 Page 70

Given 3.14 is a double constant.

To specify 3.14 as long double, we have to add L to the 3.14. (i.e 3.14L)

3. Which statement will you add in the following program to work it correctly?

#include<stdio.h>

int main()

{

printf("%f\n", log(36.0));

return 0;

}

A. #include<conio.h> B. #include<math.h>

C. #include<stdlib.h> D. #include<dos.h>

Answer & Explanation

Answer: Option B

Explanation:

math.h is a header file in the standard library of C programming language designed for basic

mathematical operations.

Declaration syntax: double log(double);

4. What will be the output of the program?

#include<stdio.h>

int main()

{

float *p;

printf("%d\n", sizeof(p));

return 0;

}

A. 2 in 16bit compiler, 4 in 32bit compiler

B. 4 in 16bit compiler, 2 in 32bit compiler

C. 4 in 16bit compiler, 4 in 32bit compiler

D. 2 in 16bit compiler, 2 in 32bit compiler

Answer: Option A

Explanation:

sizeof(x) returns the size of x in bytes.

float *p is a pointer to a float.

Page 71: EXPRESSIONS - Google Groups

DURGA SOFTAWARE SOLUTIONS

CRT-C Language

DURGA SOFTWARE SOLUTIONS, 23/3RT, 2nd Floor. Opp: Reebok Shoe Room, Near Andhra Bank S.R Nagar, Hyderabad. Cell: 9246212143, Ph: 040-64512786 Page 71

In 16 bit compiler, the pointer size is always 2 bytes.

In 32 bit compiler, the pointer size is always 4 bytes.

5. What will be the output of the program?

#include<stdio.h>

int main()

{

float fval=7.987;

printf("%d\n", (int)fval);

return 0;

}

A. 0 B. 0.0

C. 7.0 D. 7

Answer: Option D

Explanation:

printf("%d\n", (int)fval); It prints '7'. because, we typecast the (int)fval in to integer. It converts

the float value to the nearest integer value.

6. What will be the output of the program?

#include<stdio.h>

#include<math.h>

int main()

{

printf("%f\n", sqrt(49.0));

return 0;

}

A. 7.0 B. 7

C. 7.000000 D. Error: Prototype sqrt() not found.

Answer & Explanation

Answer: Option C

Explanation:

printf("%f\n", sqrt(49.0)); It prints the square root of 49 in the float format(i.e 7.000000).

Declaration Syntax: double sqrt(double x) calculates and return the positive square root of the

given number.

7. What will be the output of the program?

Page 72: EXPRESSIONS - Google Groups

DURGA SOFTAWARE SOLUTIONS

CRT-C Language

DURGA SOFTWARE SOLUTIONS, 23/3RT, 2nd Floor. Opp: Reebok Shoe Room, Near Andhra Bank S.R Nagar, Hyderabad. Cell: 9246212143, Ph: 040-64512786 Page 72

#include<stdio.h>

#include<math.h>

int main()

{

printf("%d, %d, %d\n", sizeof(3.14f), sizeof(3.14), sizeof(3.14l));

return 0;

}

A. 4, 4, 4 B. 4, 8, 8

C. 4, 8, 10 D. 4, 8, 12

Answer & Explanation

Answer: Option C

Explanation:

sizeof(3.14f) here '3.14f' specifies the float data type. Hence size of float is 4 bytes.

sizeof(3.14) here '3.14' specifies the double data type. Hence size of float is 8 bytes.

sizeof(3.14l) here '3.14l' specifies the long double data type. Hence size of float is 10 bytes.

Note: If you run the above program in Linux platform (GCC Compiler) it will give 4, 8, 12 as

output. If you run in Windows platform (TurboC Compiler) it will give 4, 8, 10 as output.

Because, C is a machine dependent language.

8. What will be the output of the program?

#include<stdio.h>

int main()

{

float f=43.20;

printf("%e, ", f);

printf("%f, ", f);

printf("%g", f);

return 0;

}

A. 4.320000e+01

, 43.200001, 43.2 B. 4.3, 43.22, 43.21

C. 4.3e, 43.20f, 43.00 D. Error

Answer & Explanation

Answer: Option A

Explanation:

Page 73: EXPRESSIONS - Google Groups

DURGA SOFTAWARE SOLUTIONS

CRT-C Language

DURGA SOFTWARE SOLUTIONS, 23/3RT, 2nd Floor. Opp: Reebok Shoe Room, Near Andhra Bank S.R Nagar, Hyderabad. Cell: 9246212143, Ph: 040-64512786 Page 73

printf("%e, ", f); Here '%e' specifies the "Scientific Notation" format. So, it prints the 43.20 as

4.320000e+01

.

printf("%f, ", f); Here '%f' specifies the "Decimal Floating Point" format. So, it prints the 43.20

as 43.200001.

printf("%g, ", f); Here '%g' "Use the shorter of %e or %f". So, it prints the 43.20 as 43.2.

9. What will be the output of the program?

#include<stdio.h>

#include<math.h>

int main()

{

float n=1.54;

printf("%f, %f\n", ceil(n), floor(n));

return 0;

}

A. 2.000000, 1.000000 B. 1.500000, 1.500000

C. 1.550000, 2.000000 D. 1.000000, 2.000000

Answer & Explanation

Answer: Option A

Explanation:

ceil(x) round up the given value. It finds the smallest integer not < x.

floor(x) round down the given value. It finds the smallest integer not > x.

printf("%f, %f\n", ceil(n), floor(n)); In this line ceil(1.54) round up the 1.54 to 2 and floor(1.54)

round down the 1.54 to 1.

In the printf("%f, %f\n", ceil(n), floor(n)); statement, the format specifier "%f %f" tells output to

be float value. Hence it prints 2.000000 and 1.000000.

10. What will be the output of the program?

#include<stdio.h>

int main()

{

float d=2.25;

printf("%e,", d);

printf("%f,", d);

printf("%g,", d);

printf("%lf", d);

Page 74: EXPRESSIONS - Google Groups

DURGA SOFTAWARE SOLUTIONS

CRT-C Language

DURGA SOFTWARE SOLUTIONS, 23/3RT, 2nd Floor. Opp: Reebok Shoe Room, Near Andhra Bank S.R Nagar, Hyderabad. Cell: 9246212143, Ph: 040-64512786 Page 74

return 0;

}

A. 2.2, 2.50, 2.50, 2.5

B. 2.2e, 2.25f, 2.00, 2.25

C. 2.250000e+000, 2.250000, 2.25, 2.250000

D. Error

Answer & Explanation

Answer: Option C

Explanation:

printf("%e,", d); Here '%e' specifies the "Scientific Notation" format. So, it prints the 2.25 as

2.250000e+000

.

printf("%f,", d); Here '%f' specifies the "Decimal Floating Point" format. So, it prints the 2.25 as

2.250000.

printf("%g,", d); Here '%g' "Use the shorter of %e or %f". So, it prints the 2.25 as 2.25.

printf("%lf,", d); Here '%lf' specifies the "Long Double" format. So, it prints the 2.25 as

2.250000.

Page 75: EXPRESSIONS - Google Groups

DURGA SOFTAWARE SOLUTIONS

CRT-C Language

DURGA SOFTWARE SOLUTIONS, 23/3RT, 2nd Floor. Opp: Reebok Shoe Room, Near Andhra Bank S.R Nagar, Hyderabad. Cell: 9246212143, Ph: 040-64512786 Page 75

Functions

1. The keyword used to transfer control from a function back to the calling function is

A. switch B. goto

C. go back D. return

Answer & Explanation

Answer: Option D

Explanation:

The keyword return is used to transfer control from a function back to the calling function.

2.void main()

{

static int var = 5;

printf("%d ",var--);

if(var)

main();

}

Answer:

5 4 3 2 1

A. 5 5 5 5 5 B. 0 0 0 0 0 C. 5 4 3 2 1 D. infinite loop

Explanation:

When static storage class is given, it is initialized once. The change in the

value of a static variable is retained even between the function calls. Main is also treated like

any other ordinary function, which can be called recursively.

3.void main()

{

extern int i;

i=20;

printf("%d",i);

}

Answer:

Page 76: EXPRESSIONS - Google Groups

DURGA SOFTAWARE SOLUTIONS

CRT-C Language

DURGA SOFTWARE SOLUTIONS, 23/3RT, 2nd Floor. Opp: Reebok Shoe Room, Near Andhra Bank S.R Nagar, Hyderabad. Cell: 9246212143, Ph: 040-64512786 Page 76

Linker Error : Undefined symbol '_i'

A. Compilation error B. Linker Error C. 0 D. 20

Explanation:

extern storage class in the following declaration,

extern int i;

specifies to the compiler that the memory for i is allocated in some other program and that

address will be given to the current program at the time of linking. But linker finds that no

other variable of name i is available in any other program with memory space allocated for it.

Hence a linker error has occurred .

4. What is the notation for following functions?

1. int f(int a, float b)

{

/* Some code */

}

2. int f(a, b)

int a; float b;

{

/* Some code */

}

A.

1. KR Notation

2. ANSI Notation B.

1. Pre ANSI C Notation

2. KR Notation

C.

1. ANSI Notation

2. KR Notation D.

1. ANSI Notation

2. Pre ANSI Notation

Answer & Explanation

Answer: Option C

Explanation:

KR Notation means Kernighan and Ritche Notation.

5.Will the following code compile

void main()

{

extern out;

printf("%d", out);

}

int out=100;

A. Yes B. No

Answer:

Page 77: EXPRESSIONS - Google Groups

DURGA SOFTAWARE SOLUTIONS

CRT-C Language

DURGA SOFTWARE SOLUTIONS, 23/3RT, 2nd Floor. Opp: Reebok Shoe Room, Near Andhra Bank S.R Nagar, Hyderabad. Cell: 9246212143, Ph: 040-64512786 Page 77

A.yes

Output: 100

Explanation:

This is the correct way of writing the previous program.

6. Will the following code compile

main()

{

show();

}

void show()

{

printf("I'm the greatest");

}

A. Yes B. No

Answer:

B. No

Compier error: Type mismatch in redeclaration of show.

Explanation:

When the compiler sees the function show it doesn't know anything about it.

So the default return type (ie, int) is assumed. But when compiler sees the

actual definition of show mismatch occurs since it is declared as void. Hence

the error.

The solutions are as follows:

1. declare void show() in main() .

2. define show() before main().

3. declare extern void show() before the use of show().

7.. How many times the program will print "Durga Exams" ?

#include<stdio.h>

int main()

{

printf("Durga Exams");

main();

return 0;

}

A. Infinite times B. 32767 times

C. 65535 times D. Till stack doesn't overflow

Answer & Explanation

Page 78: EXPRESSIONS - Google Groups

DURGA SOFTAWARE SOLUTIONS

CRT-C Language

DURGA SOFTWARE SOLUTIONS, 23/3RT, 2nd Floor. Opp: Reebok Shoe Room, Near Andhra Bank S.R Nagar, Hyderabad. Cell: 9246212143, Ph: 040-64512786 Page 78

Answer: Option D

Explanation:

A call stack or function stack is used for several related purposes, but the main reason for having

one is to keep track of the point to which each active subroutine should return control when it

finishes executing. A stack overflow occurs when too much memory is used on the call stack.

Here function main() is called repeatedly and its return address is stored in the stack. After stack

memory is full. It shows stack overflow error.

8.Will the following code compile

void main()

{

printf("%d", out);

}

int out=100;

A. Yes B. No

Answer:

B.No

Compiler error: undefined symbol out in function main.

Explanation:

The rule is that a variable is available for use from the point of declaration.

Even though a is a global variable, it is not available for main. Hence an error.

9. What will be the output of the program?

#include<stdio.h>

int main()

{

int fun();

int i;

i = fun();

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

return 0;

}

int fun()

{

_AX = 19;

}

A. Garbage value B. 0 (Zero)

C. 19 D. No output

Answer & Explanation

Page 79: EXPRESSIONS - Google Groups

DURGA SOFTAWARE SOLUTIONS

CRT-C Language

DURGA SOFTWARE SOLUTIONS, 23/3RT, 2nd Floor. Opp: Reebok Shoe Room, Near Andhra Bank S.R Nagar, Hyderabad. Cell: 9246212143, Ph: 040-64512786 Page 79

Answer: Option C

Explanation: Turbo C (Windows): The return value of the function is taken from the Accumulator _AX=1990.

But it may not work as expected in GCC compiler (Linux).

10. Will the following code compile

void main()

{

main();

}

A. Yes B. No

Answer:

A. Yes

Runtime error : Stack overflow.

Explanation:

main function calls itself again and again. Each time the function is called its

return address is stored in the call stack. Since there is no condition to

terminate the function call, the call stack overflows at runtime. So it

terminates the program and results in an error.

11. What will be the output of the program?

#include<stdio.h>

void fun(int*, int*);

int main()

{

int i=5, j=2;

fun(&i, &j);

printf("%d, %d", i, j);

return 0;

}

void fun(int *i, int *j)

{

*i = *i**i;

*j = *j**j;

}

A. 5, 2 B. 10, 4

C. 2, 5 D. 25, 4

Answer & Explanation

Answer: Option D

Page 80: EXPRESSIONS - Google Groups

DURGA SOFTAWARE SOLUTIONS

CRT-C Language

DURGA SOFTWARE SOLUTIONS, 23/3RT, 2nd Floor. Opp: Reebok Shoe Room, Near Andhra Bank S.R Nagar, Hyderabad. Cell: 9246212143, Ph: 040-64512786 Page 80

Explanation:

Step 1: int i=5, j=2; Here variable i and j are declared as an integer type and initialized to 5 and 2

respectively.

Step 2: fun(&i, &j); Here the function fun() is called with two parameters &i and &j (The &

denotes call by reference. So the address of the variable i and j are passed. )

Step 3: void fun(int *i, int *j) This function is called by reference, so we have to use * before the

parameters.

Step 4: *i = *i**i; Here *i denotes the value of the variable i. We are multiplying 5*5 and

storing the result 25 in same variable i.

Step 5: *j = *j**j; Here *j denotes the value of the variable j. We are multiplying 2*2 and

storing the result 4 in same variable j.

Step 6: Then the function void fun(int *i, int *j) return back the control back to main() function.

Step 7: printf("%d, %d", i, j); It prints the value of variable i and j.

Hence the output is 25, 4.

12. int i=10;

void main()

{

extern int i;

{

int i=20;

{

unsigned i=30;

printf("%d",i);

}

printf("%d",i);

}

printf("%d",i);

}

A. 10 20 30 B. 30 20 10 C. 10 10 10 D. 20 20 20

Answer:

B.30,20,10

Explanation:

'{' introduces new block and thus new scope. In the innermost block i is

declared as,unsigned which is a valid declaration. i is assumed of type int. So printf prints 30. In

thenext block, i has value 20 and so printf prints 20. In the outermost block, i is declared as

extern, so no storage space is allocated for it. After compilation is over the linker resolves it to

global variable i (since it is the only variable visible there). So it prints i's value as 10.

13. What will be the output of the program?

#include<stdio.h>

int i;

int fun();

int main()

Page 81: EXPRESSIONS - Google Groups

DURGA SOFTAWARE SOLUTIONS

CRT-C Language

DURGA SOFTWARE SOLUTIONS, 23/3RT, 2nd Floor. Opp: Reebok Shoe Room, Near Andhra Bank S.R Nagar, Hyderabad. Cell: 9246212143, Ph: 040-64512786 Page 81

{

while(i)

{

fun();

main();

}

printf("Hello\n");

return 0;

}

int fun()

{

printf("Hi");

}

A. Hello B. Hi Hello

C. No output D. Infinite loop

Answer & Explanation

Answer: Option A

Explanation:

Step 1: int i; The variable i is declared as an integer type.

Step 1: int fun(); This prototype tells the compiler that the function fun() does not accept any

arguments and it returns an integer value.

Step 1: while(i) The value of i is not initialized so this while condition is failed. So, it does not

execute the while block.

Step 1: printf("Hello\n"); It prints "Hello".

Hence the output of the program is "Hello"

14 #include<stdio.h>

void main()

{

register i=5;

char j[]= "hello";

printf("%s %d",j,i);

}

A. hello 5 B. 5 hello C. error D. none of the above

Answer:

A. hello 5

Explanation:

Page 82: EXPRESSIONS - Google Groups

DURGA SOFTAWARE SOLUTIONS

CRT-C Language

DURGA SOFTWARE SOLUTIONS, 23/3RT, 2nd Floor. Opp: Reebok Shoe Room, Near Andhra Bank S.R Nagar, Hyderabad. Cell: 9246212143, Ph: 040-64512786 Page 82

if you declare i as register compiler will treat it as ordinary integer and it will

take integer value. i value may be stored either in register or in memory.

15. What will be the output of the program?

#include<stdio.h>

int reverse(int);

int main()

{

int no=5;

reverse(no);

return 0;

}

int reverse(int no)

{

if(no == 0)

return 0;

else

printf("%d,", no);

reverse (no--);

}

A. Print 5, 4, 3, 2, 1 B. Print 1, 2, 3, 4, 5

C. Print 5, 4, 3, 2, 1, 0 D. Infinite loop

Answer & Explanation

Answer: Option D

Explanation:

Step 1: int no=5; The variable no is declared as integer type and initialized to 5.

Step 2: reverse(no); becomes reverse(5); It calls the function reverse() with '5' as parameter.

The function reverse accept an integer number 5 and it returns '0'(zero) if(5 == 0) if the given

number is '0'(zero) or else printf("%d,", no); it prints that number 5 and calls the function

reverse(5);.

The function runs infinetely because the there is a post-decrement operator is used. It will not

decrease the value of 'n' before calling the reverse() function. So, it calls reverse(5) infinitely.

Note: If we use pre-decrement operator like reverse(--n), then the output will be 5, 4, 3, 2, 1.

Because before calling the function, it decrements the value of 'n'.

16.Will the following code compile

void main()

Page 83: EXPRESSIONS - Google Groups

DURGA SOFTAWARE SOLUTIONS

CRT-C Language

DURGA SOFTWARE SOLUTIONS, 23/3RT, 2nd Floor. Opp: Reebok Shoe Room, Near Andhra Bank S.R Nagar, Hyderabad. Cell: 9246212143, Ph: 040-64512786 Page 83

{

int i=_l_abc(10);

printf("%d\n",--i);

}

int _l_abc(int i)

{

return(i++);

}

A. Yes B. No

Answer:

A. Yes

Output: 9

Explanation:

return(i++) it will first return i and then increments. i.e. 10 will be returned.

17. What will be the output of the program?

#include<stdio.h>

void fun(int);

int main()

{

int a=3;

fun(a);

return 0;

}

void fun(int n)

{

if(n > 0)

{

fun(--n);

printf("%d,", n);

fun(--n);

}

}

Answer: Option D

Explanation :

Function calls are stored in stack, that is LAST IN FIRST OUT.

1.fun(a=3)---calling sub function--->fun(n=3).

2.fun(3)->if(3>0)true{fun(2)-->step 3,print(n),fun(--n)//active}

3.fun(2)->if(2>0)true{fun(1)-->step 4,print(n),fun(--n)//active}

4.fun(1)->if(1>0)true{fun(0)-->step 5,print(n),fun(--n)//active}

5.fun(0)->if(0>0)false;

Page 84: EXPRESSIONS - Google Groups

DURGA SOFTAWARE SOLUTIONS

CRT-C Language

DURGA SOFTWARE SOLUTIONS, 23/3RT, 2nd Floor. Opp: Reebok Shoe Room, Near Andhra Bank S.R Nagar, Hyderabad. Cell: 9246212143, Ph: 040-64512786 Page 84

6.From step 4,{fun(n=0)//finished,PRINT(n=0),fun(-1)-->step 7}

7.fun(-1)->if(-1>0)false;

8.From step 3,{fun(n=1)//finished,PRINT(n=1),fun(0)-->step 9}

9.fun(0)->if(0>0)false;

10.From step 2,{fun(n=2)//finished,PRINT(n=2),fun(1)-->step 11}

11.fun(1)->if(1>0)true{fun(0)->step 12,print(n),fun(--n)//acti}

12.fun(0)->if(0>0)false;

13.From 11,{fun(n=0)//finished,PRINT(0),fun(-1)-->step 14}

14.fun(-1)->if(-1>0)false;

18. Will the code convert lower case to upper case

void main()

{

char c=' ',x,convert(z);

getc(c);

if((c>='a') && (c<='z'))

x=convert(c);

printf("%c",x);

}

convert(z)

{

return z-32;

}

A. Yes B. No

Answer:

B. No

Compiler error

Explanation:

declaration of convert and format of getc() are wrong.

19. void main(int argc, char **argv)

{

printf("enter the character");

getchar();

sum(argv[1],argv[2]);

}

sum(num1,num2)

int num1,num2;

{

return num1+num2;

}

Page 85: EXPRESSIONS - Google Groups

DURGA SOFTAWARE SOLUTIONS

CRT-C Language

DURGA SOFTWARE SOLUTIONS, 23/3RT, 2nd Floor. Opp: Reebok Shoe Room, Near Andhra Bank S.R Nagar, Hyderabad. Cell: 9246212143, Ph: 040-64512786 Page 85

Answer:

Compiler error.

Explanation:

argv[1] & argv[2] are strings. They are passed to the function sum without

converting it to integer values.

20. # include <stdio.h>

int one_d[]={1,2,3};

main()

{

int *ptr;

ptr=one_d;

ptr+=3;

printf("%d",*ptr);

}

A. 1 B.2 C.3 D. garbage value

Answer:

D. garbage value

Explanation:

ptr pointer is pointing to out of the array range of one_d.

21. # include<stdio.h>

aaa() {

printf("hi");

}

bbb(){

printf("hello");

}

ccc(){

printf("bye");

}

main()

{

int (*ptr[3])();

ptr[0]=aaa;

ptr[1]=bbb;

ptr[2]=ccc;

ptr[2]();

}

A.hi B.hello C.bye D.error

Answer:

C.bye

Explanation:

Page 86: EXPRESSIONS - Google Groups

DURGA SOFTAWARE SOLUTIONS

CRT-C Language

DURGA SOFTWARE SOLUTIONS, 23/3RT, 2nd Floor. Opp: Reebok Shoe Room, Near Andhra Bank S.R Nagar, Hyderabad. Cell: 9246212143, Ph: 040-64512786 Page 86

ptr is array of pointers to functions of return type int.ptr[0] is assigned to

address of the function aaa. Similarly ptr[1] and ptr[2] for bbb and ccc

respectively. ptr[2]() is in effect of writing ccc(), since ptr[2] points to ccc.

22. Will the following code compile

main()

{

int i;

i = abc();

printf("%d",i);

}

abc()

{

_AX = 1000;

}

A. Yes B. No

Answer:

Yes

1000

Explanation:

Normally the return value from the function is through the information from the

accumulator. Here _AH is the pseudo global variable denoting the

accumulator. Hence, the value of the accumulator is set 1000 so the function

returns value 1000.

23. void main()

{

extern int i;

i=20;

printf("%d",sizeof(i));

}

Answer:

Linker error: undefined symbol '_i'.

Explanation:

extern declaration specifies that the variable i is defined somewhere else. The

compiler passes the external variable to be resolved by the linker. So

compiler doesn't find an error. During linking the linker searches for the

definition of i. Since it is not found the linker flags an error.

24. What will be the output of the program?

#include<stdio.h>

int sumdig(int);

Page 87: EXPRESSIONS - Google Groups

DURGA SOFTAWARE SOLUTIONS

CRT-C Language

DURGA SOFTWARE SOLUTIONS, 23/3RT, 2nd Floor. Opp: Reebok Shoe Room, Near Andhra Bank S.R Nagar, Hyderabad. Cell: 9246212143, Ph: 040-64512786 Page 87

int main()

{

int a, b;

a = sumdig(123);

b = sumdig(123);

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

return 0;

}

int sumdig(int n)

{

int s, d;

if(n!=0)

{

d = n%10;

n = n/10;

s = d+sumdig(n);

}

else

return 0;

return s;

}

A. 4, 4 B. 3, 3 C. 6, 6 D. 12, 12

Answer: Option C

sumdig(123)

n=123 which != 0,so n will enter into the loop.now in the loop the values of d,n,s are

3(123%10),12(123/10),3+sumdig(12)[which will recurcive call .so finally we will get the value

for s is 6(3+2+1)

25. What will be the output of the program?

#include<stdio.h>

int main()

{

void fun(char*);

char a[100];

a[0] = 'A'; a[1] = 'B';

a[2] = 'C'; a[3] = 'D';

fun(&a[0]);

return 0;

}

void fun(char *a)

{

a++;

Page 88: EXPRESSIONS - Google Groups

DURGA SOFTAWARE SOLUTIONS

CRT-C Language

DURGA SOFTWARE SOLUTIONS, 23/3RT, 2nd Floor. Opp: Reebok Shoe Room, Near Andhra Bank S.R Nagar, Hyderabad. Cell: 9246212143, Ph: 040-64512786 Page 88

printf("%c", *a);

a++;

printf("%c", *a);

}

[A]. AB [B]. BC

[C]. CD [D]. No output

Answer: Option B

Explanation:

Here we pass the array in function. We pass the base address of the base array which is zero.

a[0]=A, a[1]=B, a[2]=C, a[3]=D.

Now a++ it means increment the address of the address 1 which store the value is B. In same a++

it will be 2, which print C.

26. What will be the output of the program?

#include<stdio.h>

int fun(int, int);

typedef int (*pf) (int, int);

int proc(pf, int, int);

int main()

{

printf("%d\n", proc(fun, 6, 6));

return 0;

}

int fun(int a, int b)

{

return (a==b);

}

int proc(pf p, int a, int b)

{

return ((*p)(a, b));

}

[A]. 6 [B]. 1

[C]. 0 [D]. -1

Answer: Option B

Explanation:

HINTS : consider printf in main takes Number of char,

step 1 : proc(fun, 6, 6) in printf of main call int proc(pf p, int a, int b)

Page 89: EXPRESSIONS - Google Groups

DURGA SOFTAWARE SOLUTIONS

CRT-C Language

DURGA SOFTWARE SOLUTIONS, 23/3RT, 2nd Floor. Opp: Reebok Shoe Room, Near Andhra Bank S.R Nagar, Hyderabad. Cell: 9246212143, Ph: 040-64512786 Page 89

step 2: return ((*p)(a, b)); call int fun(int a, int b)

step 3: return (a==b); //here a=6;b=6; a==b means 6==6 then condition is true so it is 1;

return 1;

27. What will be the output of the program?

#include<stdio.h>

int main()

{

int i=1;

if(!i)

printf("Durga Exams");

else

{

i=0;

printf("C-Program");

main();

}

return 0;

}

A. prints " Durga Exams, C-Program" infinitely

B. prints "C-Program" infinetly

C. prints "C-Program, Durga Exams " infinitely

D. Error: main() should not inside else statement

Answer & Explanation

Answer: Option B

Explanation:

Step 1: int i=1; The variable i is declared as an integer type and initialized to 1(one).

Step 2: if(!i) Here the !(NOT) operator reverts the i value 1 to 0. Hence the if(0) condition fails.

So it goes to else part.

Step 3: else { i=0; In the else part variable i is assigned to value 0(zero).

Step 4: printf("C-Program"); It prints the "C-program".

Step 5: main(); Here we are calling the main() function.

After calling the function, the program repeats from step 1 to step 5 infinitely.

Hence it prints "C-Program" infinitely.

28. What will be the output of the program?

#include<stdio.h>

int main()

{

int i=3, j=4, k, l;

k = addmult(i, j);

Page 90: EXPRESSIONS - Google Groups

DURGA SOFTAWARE SOLUTIONS

CRT-C Language

DURGA SOFTWARE SOLUTIONS, 23/3RT, 2nd Floor. Opp: Reebok Shoe Room, Near Andhra Bank S.R Nagar, Hyderabad. Cell: 9246212143, Ph: 040-64512786 Page 90

l = addmult(i, j);

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

return 0;

}

int addmult(int ii, int jj);

{

int kk, ll;

kk = ii + jj;

ll = ii * jj;

return (kk, ll);

}

A. Function addmult()return 7 and 12

B. No output

C. Error: Compile error

D. None of above

Answer & Explanation

Answer: Option C

Explanation:

There is an error in this statement int addmult(int ii, int jj);. We have to remove the semi-colon,

because it was an definition of the function addmult()

29. What will be the output of the program?

#include<stdio.h>

int i;

int fun1(int);

int fun2(int);

int main()

{

extern int j;

int i=3;

fun1(i);

printf("%d,", i);

fun2(i);

printf("%d", i);

return 0;

}

int fun1(int j)

{

printf("%d,", ++j);

return 0;

Page 91: EXPRESSIONS - Google Groups

DURGA SOFTAWARE SOLUTIONS

CRT-C Language

DURGA SOFTWARE SOLUTIONS, 23/3RT, 2nd Floor. Opp: Reebok Shoe Room, Near Andhra Bank S.R Nagar, Hyderabad. Cell: 9246212143, Ph: 040-64512786 Page 91

}

int fun2(int i)

{

printf("%d,", ++i);

return 0;

}

int j=1;

A. 3, 4, 4, 3 B. 4, 3, 4, 3

C. 3, 3, 4, 4 D. 3, 4, 3, 4

Answer & Explanation

Answer: Option B

Explanation:

Step 1: int i; The variable i is declared as an global and integer type.

Step 2: int fun1(int); This prototype tells the compiler that the fun1() accepts the one integer

parameter and returns the integer value.

Step 3: int fun2(int); This prototype tells the compiler that the fun2() accepts the one integer

parameter and returns the integer value.

Step 4: extern int j; Inside the main function, the extern variable j is declared and defined in

another source file.

Step 5: int i=3; The local variable i is defines as an integer type and initialized to 3.

Step 6: fun1(i); The fun1(i) increements the given value of variable i prints it. Here fun1(i)

becomes fun1(3) hence it prints '4' then the control is given back to the main function.

Step 7: printf("%d,", i); It prints the value of local variable i. So, it prints '3'.

Step 8: fun2(i); The fun2(i) increements the given value of variable i prints it. Here fun2(i)

becomes fun2(3) hence it prints '4' then the control is given back to the main function.

Step 9: printf("%d,", i); It prints the value of local variable i. So, it prints '3'.

Hence the output is "4 3 4 3"

30. What will be the output of the program?

#include<stdio.h>

int func1(int);

int main()

{

int k=35;

k = func1(k=func1(k=func1(k)));

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

return 0;

}

int func1(int k)

{

k++;

Page 92: EXPRESSIONS - Google Groups

DURGA SOFTAWARE SOLUTIONS

CRT-C Language

DURGA SOFTWARE SOLUTIONS, 23/3RT, 2nd Floor. Opp: Reebok Shoe Room, Near Andhra Bank S.R Nagar, Hyderabad. Cell: 9246212143, Ph: 040-64512786 Page 92

return k;

}

A. k=35 B. k=36

C. k=37 D. k=38

Answer & Explanation

Answer: Option D

Explanation:

Step 1: int k=35; The variable k is declared as an integer type and initialized to 35.

Step 2: k = func1(k=func1(k=func1(k))); The func1(k) increement the value of k by 1 and return

it. Here the func1(k) is called 3 times. Hence it increements value of k = 35 to 38. The result is

stored in the variable k = 38.

Step 3: printf("k=%d\n", k); It prints the value of variable k "38".

31. What will be the output of the program?

#include<stdio.h>

int fun(int(*)());

int main()

{

fun(main);

printf("Hi\n");

return 0;

}

int fun(int (*p)())

{

printf("Hello ");

return 0;

}

[A]. Infinite loop [B]. Hi

[C]. Hello Hi

[D]. Error

Answer: Option C

Explanation:

first fun(main) is called so fun function is invoked which takes the address of main() function

and print the HELLO after that it will be return and it print the Hi

so that the finaly output is

Page 93: EXPRESSIONS - Google Groups

DURGA SOFTAWARE SOLUTIONS

CRT-C Language

DURGA SOFTWARE SOLUTIONS, 23/3RT, 2nd Floor. Opp: Reebok Shoe Room, Near Andhra Bank S.R Nagar, Hyderabad. Cell: 9246212143, Ph: 040-64512786 Page 93

hello hi..

32. What will be the output of the program?

#include<stdio.h>

int main()

{

int fun(int);

int i=3;

fun(i=fun(fun(i)));

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

return 0;

}

fun(int i)

{

i++;

return i;

}

A. 5 B. 4

C. Error D. Garbage value

Answer & Explanation

Answer: Option A

Explanation:

Step 1: int fun(int); This is prototype of function fun(). It tells the compiler that the function

fun() accept one integer parameter and returns an integer value.

Step 2: int i=3; The variable i is declared as an integer type and initialized to value 3.

Step 3: fun(i=fun(fun(i)));. The function fun(i) increements the value of i by 1(one) and return it.

Lets go step by step,

=> fun(i) becomes fun(3) is called and it returns 4.

=> i = fun(fun(i)) becomes i = fun(4) is called and it returns 5 and stored in variable i.(i=5)

=> fun(i=fun(fun(i))); becomes fun(5); is called and it return 6 and nowhere the return value is

stored.

Step 4: printf("%d\n", i); It prints the value of variable i.(5)

Page 94: EXPRESSIONS - Google Groups

DURGA SOFTAWARE SOLUTIONS

CRT-C Language

DURGA SOFTWARE SOLUTIONS, 23/3RT, 2nd Floor. Opp: Reebok Shoe Room, Near Andhra Bank S.R Nagar, Hyderabad. Cell: 9246212143, Ph: 040-64512786 Page 94

Hence the output is '5'.

33.Point out the error in the program

f(int a, int b)

{

int a;

a = 20;

return a;

}

A. Missing parenthesis in return statement

B. The function should be defined as int f(int a, int b)

C. Redeclaration of a

D. None of above

Answer & Explanation

Answer: Option C

Explanation:

f(int a, int b) The variable a is declared in the function argument statement.

int a; Here again we are declaring the variable a. Hence it shows the error "Redeclaration of a"

34. Which of the following statements are correct about the program?

#include<stdio.h>

int main()

{

printf("%p\n", main());

return 0;

}

A. It prints garbage values infinitely

B. Runs infinitely without printing anything

C. Error: main() cannot be called inside printf()

D. No Error and print nothing

Answer & Explanation

Answer: Option B

Explanation:

In printf("%p\n", main()); it calls the main() function and then it repeats infinetly, untill stack

overflow.

Page 95: EXPRESSIONS - Google Groups

DURGA SOFTAWARE SOLUTIONS

CRT-C Language

DURGA SOFTWARE SOLUTIONS, 23/3RT, 2nd Floor. Opp: Reebok Shoe Room, Near Andhra Bank S.R Nagar, Hyderabad. Cell: 9246212143, Ph: 040-64512786 Page 95

35. There is a error in the below program. Which statement will you add to remove it?

#include<stdio.h>

int main()

{

int a;

a = f(10, 3.14);

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

return 0;

}

float f(int aa, float bb)

{

return ((float)aa + bb);

}

A. Add prototype: float f(aa, bb)

B. Add prototype: float f(int, float)

C. Add prototype: float f(float, int)

D. Add prototype: float f(bb, aa)

Answer & Explanation

Answer: Option B

Explanation:

This program will create an error "Type mismatch in redeclaration of f". To overcome this error,

we have to add function prototype of f.

The correct form of function f prototype is float f(int, float);

36. Which of the following statements are correct about the function?

long fun(int num)

{

int i;

long f=1;

for(i=1; i<=num; i++)

f = f * i;

return f;

}

A. The function calculates the value of 1 raised to power num.

B. The function calculates the square root of an integer

C. The function calculates the factorial value of an integer

D. None of above

Answer & Explanation

Answer: Option C

Page 96: EXPRESSIONS - Google Groups

DURGA SOFTAWARE SOLUTIONS

CRT-C Language

DURGA SOFTWARE SOLUTIONS, 23/3RT, 2nd Floor. Opp: Reebok Shoe Room, Near Andhra Bank S.R Nagar, Hyderabad. Cell: 9246212143, Ph: 040-64512786 Page 96

Explanation:

Yes, this function calculates and return the factorial value of an given integer num.

22. A function cannot be defined inside another function

A. True B. False

Answer & Explanation

Answer: Option A

Explanation:

A function cannot be defined inside the another function, but a function can be called inside a

another function.

37. Functions cannot return more than one value at a time

A. True B. False

Answer & Explanation

Answer: Option A

Explanation:

True, A function cannot return more than one value at a time. because after returning a value the

control is given back to calling function.

But if you want return multiple values from function return structure type.

37. If return type for a function is not specified, it defaults to int

A. True B. False

Answer & Explanation

Answer: Option A

Explanation:

True, The default return type for a function is int.

38. In C all functions except main() can be called recursively.

A. True B. False

Page 97: EXPRESSIONS - Google Groups

DURGA SOFTAWARE SOLUTIONS

CRT-C Language

DURGA SOFTWARE SOLUTIONS, 23/3RT, 2nd Floor. Opp: Reebok Shoe Room, Near Andhra Bank S.R Nagar, Hyderabad. Cell: 9246212143, Ph: 040-64512786 Page 97

Answer & Explanation

Answer: Option B

Explanation:

Any function including main() can be called recursively.

39. Functions can be called either by value or reference

A. True B. False

Answer & Explanation

Answer: Option A

Explanation:

True, A function can be called either call by value or call by reference.

Example:

Call by value means c = sub(a, b); here value of a and b are passed.

Call by reference or address or pointer means c = sub(&a, &b); here address of a and b are

passed.

40. Names of functions in two different files linked together must be unique

A. True B. False

Answer & Explanation

Answer: Option A

Explanation:

True, If two function are declared in a same name, it gives "Error: Multiple declaration of

function_name())".

41. A function may have any number of return statements each returning different values.

A. True B. False

Answer: Option A

Explanation:

Page 98: EXPRESSIONS - Google Groups

DURGA SOFTAWARE SOLUTIONS

CRT-C Language

DURGA SOFTWARE SOLUTIONS, 23/3RT, 2nd Floor. Opp: Reebok Shoe Room, Near Andhra Bank S.R Nagar, Hyderabad. Cell: 9246212143, Ph: 040-64512786 Page 98

True, A function may have any number of return statements each returning different values and

each return statements will not occur successively.

Eg:

int fun(int a,int b)

{

if(a>b)

return a;

else

return b;

}

42. Names of functions in two different files linked together must be unique

A. True B. False

Answer & Explanation

Answer: Option A

Explanation:

True, If two function are declared in a same name, it gives "Error: Multiple declaration of

function_name())".

Page 99: EXPRESSIONS - Google Groups

DURGA SOFTAWARE SOLUTIONS

CRT-C Language

DURGA SOFTWARE SOLUTIONS, 23/3RT, 2nd Floor. Opp: Reebok Shoe Room, Near Andhra Bank S.R Nagar, Hyderabad. Cell: 9246212143, Ph: 040-64512786 Page 99

Library Functions

1.What will the function rewind() do?

A. Reposition the file pointer to a character reverse.

B. Reposition the file pointer stream to end of file.

C. Reposition the file pointer to begining of that line.

D. Reposition the file pointer to begining of file.

Answer & Explanation

Answer: Option D

Explanation:

rewind() takes the file pointer to the beginning of the file. so that the next I/O operation will take

place at the beginning of the file.

Example: rewind(FilePointer);

2. Input/output function prototypes and macros are defined in which header file?

A. conio.h B. stdlib.h

C. stdio.h D. dos.h

Answer & Explanation

Answer: Option C

Explanation:

stdio.h, which stands for "standard input/output header", is the header in the C standard library

that contains macro definitions, constants, and declarations of functions and types used for

various standard input and output operations.

3. Which standard library function will you use to find the last occurance of a character in a

string in C?

A. strnchar() B. strchar()

C. strrchar() D. strrchr()

Answer & Explanation

Answer: Option D

Explanation:

Page 100: EXPRESSIONS - Google Groups

DURGA SOFTAWARE SOLUTIONS

CRT-C Language

DURGA SOFTWARE SOLUTIONS, 23/3RT, 2nd Floor. Opp: Reebok Shoe Room, Near Andhra Bank S.R Nagar, Hyderabad. Cell: 9246212143, Ph: 040-64512786 Page 100

strrchr() returns a pointer to the last occurrence of character in a string.

Example:

#include <stdio.h>

#include <string.h>

int main()

{

char str[30] = "1234567891011121345567";

printf("The last position of '2' is %d.\n",

strrchr(str, '2') - str);

return 0;

}

Output: The last position of '2' is 14.

4. Does there any function exist to convert the int or float to a string?

A. Yes B. No

Answer & Explanation

Answer: Option A

Explanation:

1. itoa() converts an integer to a string.

2. ltoa() converts a long to a string.

3. ultoa() converts an unsigned long to a string.

4. sprintf() sends formatted output to a string, so it can be used to convert any type of values to

string type.

#include<stdio.h>

#include<stdlib.h>

int main(void)

{

int num1 = 12345;

float num2 = 5.12;

char str1[20];

char str2[20];

itoa(num1, str1, 10); /* 10 radix value */

printf("integer = %d string = %s \n", num1, str1);

Page 101: EXPRESSIONS - Google Groups

DURGA SOFTAWARE SOLUTIONS

CRT-C Language

DURGA SOFTWARE SOLUTIONS, 23/3RT, 2nd Floor. Opp: Reebok Shoe Room, Near Andhra Bank S.R Nagar, Hyderabad. Cell: 9246212143, Ph: 040-64512786 Page 101

sprintf(str2, "%f", num2);

printf("float = %f string = %s", num2, str2);

return 0;

}

// Output:

// integer = 12345 string = 12345

// float = 5.120000 string = 5.120000

5. Can you use the fprintf() to display the output on the screen?

A. Yes B. No

Answer & Explanation

Answer: Option A

Explanation:

Do like this fprintf(stdout, "%s %d %f", ā€œhelloā€,35,10.23);

6. What will the function randomize() do?

A. returns a random number.

B. returns a random number generator in the specified range.

C. returns a random number generator with a random value based on time.

D. return a random number with a given seed value.

Answer & Explanation

Answer: Option C

Explanation:

The randomize() function initializes the random number generator with a random value based on

time. You can try the sample program given below in Turbo-C, it may not work as expected in

other compilers.

/* Prints a random number in the range 0 to 99 */

#include <stdlib.h>

#include <stdio.h>

#include <time.h>

Page 102: EXPRESSIONS - Google Groups

DURGA SOFTAWARE SOLUTIONS

CRT-C Language

DURGA SOFTWARE SOLUTIONS, 23/3RT, 2nd Floor. Opp: Reebok Shoe Room, Near Andhra Bank S.R Nagar, Hyderabad. Cell: 9246212143, Ph: 040-64512786 Page 102

int main(void)

{

randomize();

printf("Random number in the 0-99 range: %d\n", random (100));

return 0;

}

7. What will be the output of the program?

#include<stdio.h>

int main()

{

int i;

i = printf("How r u\n");

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

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

return 0;

}

A.

How r u

7

2

B.

How r u

8

2

C.

How r u

1

1

D. Error: cannot assign printf to variable

Answer & Explanation

Answer: Option B

Explanation:

In the program, printf() returns the number of charecters printed on the console

i = printf("How r u\n"); This line prints "How r u" with a new line character and returns the

length of string printed then assign it to variable i.

So i = 8 (length of '\n' is 1).

i = printf("%d\n", i); In the previous step the value of i is 8. So it prints "8" with a new line

character and returns the length of string printed then assign it to variable i. So i = 2 (length of

'\n' is 1).

printf("%d\n", i); In the previous step the value of i is 2. So it prints "2"

8. What will be the output of the program?

#include<stdio.h>

Page 103: EXPRESSIONS - Google Groups

DURGA SOFTAWARE SOLUTIONS

CRT-C Language

DURGA SOFTWARE SOLUTIONS, 23/3RT, 2nd Floor. Opp: Reebok Shoe Room, Near Andhra Bank S.R Nagar, Hyderabad. Cell: 9246212143, Ph: 040-64512786 Page 103

#include<stdlib.h>

int main()

{

char *i = "55.555";

int result1 = 10;

float result2 = 11.111;

result1 = result1+atoi(i);

result2 = result2+atof(i);

printf("%d, %f", result1, result2);

return 0;

}

A. 55, 55.555 B. 66, 66.666600

C. 65, 66.666000 D. 55, 55

Answer & Explanation

Answer: Option C

Explanation:

Function atoi() converts the string to integer.

Function atof() converts the string to float.

result1 = result1+atoi(i);

Here result1 = 10 + atoi(55.555);

result1 = 10 + 55;

result1 = 65;

result2 = result2+atof(i);

Here result2 = 11.111 + atof(55.555);

result2 = 11.111 + 55.555000;

result2 = 66.666000;

So the output is "65, 66.666000"

9. What will be the output of the program?

#include<stdio.h>

#include<string.h>

int main()

{

char dest[] = {98, 98, 0};

char src[] = "bbb";

int i;

if((i = memcmp(dest, src, 2))==0)

Page 104: EXPRESSIONS - Google Groups

DURGA SOFTAWARE SOLUTIONS

CRT-C Language

DURGA SOFTWARE SOLUTIONS, 23/3RT, 2nd Floor. Opp: Reebok Shoe Room, Near Andhra Bank S.R Nagar, Hyderabad. Cell: 9246212143, Ph: 040-64512786 Page 104

printf("Got it");

else

printf("Missed");

return 0;

}

A. Missed B. Got it

C. Error in memcmp statement D. None of above

Answer & Explanation

Answer: Option B

Explanation:

memcmp compares the first 2 bytes of the blocks dest and src as unsigned chars. So, the ASCII

value of 98 is 'b'.

if((i = memcmp(dest, src, 2))==0) When comparing the array dest and src as unsigned chars, the

first 2 bytes are same in both variables.so memcmp returns '0'.

Then, the if(0=0) condition is satisfied. Hence the output is "Got it".

10. What will function gcvt() do?

A. Convert vector to integer value

B. Convert floating-point number to a string

C. Convert 2D array in to 1D array.

D. Covert multi Dimensional array to 1D array

Answer & Explanation

Answer: Option B

Explanation:

The gcvt() function converts a floating-point number to a string. It converts given value to a null-

terminated string.

#include <stdlib.h>

#include <stdio.h>

int main(void)

{

char str[25];

double num;

int sig = 5; /* significant digits */

/* a regular number */

Page 105: EXPRESSIONS - Google Groups

DURGA SOFTAWARE SOLUTIONS

CRT-C Language

DURGA SOFTWARE SOLUTIONS, 23/3RT, 2nd Floor. Opp: Reebok Shoe Room, Near Andhra Bank S.R Nagar, Hyderabad. Cell: 9246212143, Ph: 040-64512786 Page 105

num = 9.876;

gcvt(num, sig, str);

printf("string = %s\n", str);

/* a negative number */

num = -123.4567;

gcvt(num, sig, str);

printf("string = %s\n", str);

/* scientific notation */

num = 0.678e5;

gcvt(num, sig, str);

printf("string = %s\n", str);

return(0);

}

Output:

string = 9.876

string = -123.46

string = 67800

11. What will be the output of the program?

#include<stdio.h>

int main()

{

int i;

char c;

for(i=1; i<=5; i++)

{

scanf("%c", &c); /* given input is 'a' */

printf("%c", c);

ungetc(c, stdin);

}

return 0;

}

A. aaaa B. aaaaa

C. Garbage value. D. Error in ungetc statement.

Answer & Explanation

Answer: Option B

Explanation:

for(i=1; i<=5; i++) Here the for loop runs 5 times.

Page 106: EXPRESSIONS - Google Groups

DURGA SOFTAWARE SOLUTIONS

CRT-C Language

DURGA SOFTWARE SOLUTIONS, 23/3RT, 2nd Floor. Opp: Reebok Shoe Room, Near Andhra Bank S.R Nagar, Hyderabad. Cell: 9246212143, Ph: 040-64512786 Page 106

Loop 1:

scanf("%c", &c); Here we give 'a' as input.

printf("%c", c); prints the character 'a' which is given in the previous "scanf()" statement.

ungetc(c, stdin); "ungetc()" function pushes character 'a' back into input stream.

Loop 2:

Here the scanf("%c", &c); get the input from "stdin" because of "ungetc" function.

printf("%c", c); Now variable c = 'a'. So it prints the character 'a'.

ungetc(c, stdin); "ungetc()" function pushes character 'a' back into input stream.

This above process will be repeated in Loop 3, Loop 4, Loop 5.

12. It is necessary that for the string functions to work safely the strings must be terminated with

'\0'.

A. True B. False

Answer & Explanation

Answer: Option A

Explanation:

C string is a character sequence stored as a one-dimensional character array and terminated with

a null character('\0', called NULL in ASCII).

The length of a C string is found by searching for the (first) NULL byte.

13.The prototypes of all standard library string functions are declared in the file string.h.

A. Yes B. No

Answer & Explanation

Answer: Option A

Explanation:

string.h is the header in the C standard library for the C programming language which contains

macro definitions, constants, and declarations of functions and types used not only for string

handling but also various memory handling functions.

14. scanf() or atoi() function can be used to convert a string like "436" in to integer.

A. Yes B. No

Answer & Explanation

Page 107: EXPRESSIONS - Google Groups

DURGA SOFTAWARE SOLUTIONS

CRT-C Language

DURGA SOFTWARE SOLUTIONS, 23/3RT, 2nd Floor. Opp: Reebok Shoe Room, Near Andhra Bank S.R Nagar, Hyderabad. Cell: 9246212143, Ph: 040-64512786 Page 107

Answer: Option A

Explanation:

scanf is a function that reads data with specified format from a given string stream source.

scanf("%d",&number);

atoi() convert string to integer.

var number;

number = atoi("string");

15. Which header file should be included to use functions like malloc() and calloc()?

A. memory.h B. stdlib.h

C. string.h D. dos.h

Answer & Explanation

Answer: Option B

Explanation:

Stdlib means standard library function. Which contains malloc(),calloc(),realloc(),free() function

declarations.

16. What will be the output of the program?

#include<stdio.h>

#include<stdlib.h>

int main()

{

int *p;

p = (int *)malloc(20); /* Assume p has address of 1318 */

free(p);

printf("%u", p);

return 0;

}

[A]. 1318

[B]. Garbage value

[C]. 1316 [D]. Random address

Answer: Option A

Explanation:

Page 108: EXPRESSIONS - Google Groups

DURGA SOFTAWARE SOLUTIONS

CRT-C Language

DURGA SOFTWARE SOLUTIONS, 23/3RT, 2nd Floor. Opp: Reebok Shoe Room, Near Andhra Bank S.R Nagar, Hyderabad. Cell: 9246212143, Ph: 040-64512786 Page 108

free(p) means it deletes the memory pointed by p but not p so it prints 1318

17. What will be the output of the program?

#include<stdio.h>

#include<stdlib.h>

int main()

{

int *p;

p = (int *)malloc(20);

printf("%d\n", sizeof(p));

free(p);

return 0;

}

A. 4 B. 2

C. 8 D. Garbage value

Answer & Explanation

Answer: Option B

Explanation:

The sizeof any pointer on 16 bit dos is 2 bytes.

If it under gcc then it is 4 bytes.

18. What will be the output of the program?

#include<stdio.h>

int main()

{

char *s;

char *fun();

s = fun();

printf("%s\n", s);

return 0;

}

char *fun()

{

char buffer[30];

strcpy(buffer, "RAM");

return (buffer);

}

A. 0xffff B. Garbage value

C. 0xffee D. Error

Page 109: EXPRESSIONS - Google Groups

DURGA SOFTAWARE SOLUTIONS

CRT-C Language

DURGA SOFTWARE SOLUTIONS, 23/3RT, 2nd Floor. Opp: Reebok Shoe Room, Near Andhra Bank S.R Nagar, Hyderabad. Cell: 9246212143, Ph: 040-64512786 Page 109

Answer & Explanation

Answer: Option B

Explanation:

The output is unpredictable since buffer is an auto array and will die when the control go back to

main. Thus s will be pointing to an array , which not exists. This is also called dangling pointer.

Page 110: EXPRESSIONS - Google Groups

DURGA SOFTAWARE SOLUTIONS

CRT-C Language

DURGA SOFTWARE SOLUTIONS, 23/3RT, 2nd Floor. Opp: Reebok Shoe Room, Near Andhra Bank S.R Nagar, Hyderabad. Cell: 9246212143, Ph: 040-64512786 Page 110

Pointers 1.Can you combine the following two statements into one?

char *p;

p = (char*) malloc(10);

[A]. char p = *malloc(10);

[B]. char *p = (char) malloc(10);

[C]. char *p = (char*)malloc(10);

[D]. char *p = (char *)(malloc*)(10);

Answer: Option C

Explanation:

Malloc will allocate space dynamically by default it returns void* type so inorder to get character

pointer we need to typecast it char *.

2. what is the sizeof near, far and huge pointers in DOS?

A. near=2 far=4 huge=4 B. near=4 far=8 huge=8

C. near=2 far=4 huge=8 D. near=4 far=4 huge=4

Answer & Explanation

Answer: Option A

Explanation:

near=2, far=4 and huge=4 pointers exist only under DOS. Under windows and Linux every

pointers is 4 bytes long.

3. If a variable is a pointer to a structure, then which of the following operator is used to access

data members of the structure through the pointer variable?

A. '.' B. '&'

C. '*' D. '->'

Answer & Explanation

Answer: Option D

Explanation: ->operator is pointer to structure member

4. void main()

{

int const * p=5;

printf("%d",++(*p));

}

A.6 B.5 C.ERROR D.GARBAGE VALUE

Answer:

Compiler error: Cannot modify a constant value.

Explanation:

p is a pointer to a "constant integer". But we tried to change the value of the

"constant integer".

Page 111: EXPRESSIONS - Google Groups

DURGA SOFTAWARE SOLUTIONS

CRT-C Language

DURGA SOFTWARE SOLUTIONS, 23/3RT, 2nd Floor. Opp: Reebok Shoe Room, Near Andhra Bank S.R Nagar, Hyderabad. Cell: 9246212143, Ph: 040-64512786 Page 111

5. What would be the equivalent pointer expression for referring the array element

a[i][j][k][l][m]

[A]. ((((a+i)+j)+k)+l) [B]. *(*(*(*(*(a+i)+j)+k)+l)+m

[C]. (((a+i)+j)+k+l) [D]. ((a+i)+j+k+l)

Answer: Option B

Explanation:

For every array a const poiner with the array name will be created internally.

So arrays can be written as

a[i]---->*(a+i);---*(i+a)-- i[a]

a[i][j]---->*(*(a+i)+j);

a[i][j][k]---->*(*(*(a+i)+j)+k);

6. What will be the output of the program ?

#include<stdio.h>

int main()

{

int x=30, *y, *z;

y=&x; /* Assume address of x is 500 and integer is 4 byte size */

z=y;

*y++=*z++;

x++;

printf("x=%d, y=%d, z=%d\n", x, y, z);

return 0;

}

[A]. x=31, y=502, z=502 [B]. x=31, y=500, z=500

[C]. x=31, y=498, z=498 [D]. x=31, y=504, z=504

Answer: Option D

Explanation:

X=30

Y=&x(y<=500)

Z contains y that the address in y is copied to z(500)

*y++=*z++ means contents at *z copied to *y .after that z and y are incremented to 504

X++ means 30 is incrementd by 1 and becomes 31

Page 112: EXPRESSIONS - Google Groups

DURGA SOFTAWARE SOLUTIONS

CRT-C Language

DURGA SOFTWARE SOLUTIONS, 23/3RT, 2nd Floor. Opp: Reebok Shoe Room, Near Andhra Bank S.R Nagar, Hyderabad. Cell: 9246212143, Ph: 040-64512786 Page 112

7. main()

{

int i=-1,j=-1,k=0,l=2,m;

m=i++&&j++&&k++||l++;

printf("%d %d %d %d %d",i,j,k,l,m);

}

Answer:

0 0 1 3 1

A . -1 -1 0 2 garbage value B. 0 0 1 3 1 C.0 0 1 2 1 D. -1 -1 0 2 1

Explanation :

Logical operations always give a result of 1 or 0 . And also the logical AND

(&&) operator has higher priority over the logical OR (||) operator. So the expression ā€ži++ &&

j++ && k++ā€™ is executed first. The result of this expression is 0 (-1 && -1 && 0 = 0). Now

the expression is 0 || 2 which evaluates to 1 (because OR operator always gives 1 except for

ā€ž0 || 0ā€Ÿ combination- for which it gives 0). So the value of m is 1. The values of other variables

are also incremented by 1.

7. What will be the output of the program If the integer is 4 bytes long?

#include<stdio.h>

int main()

{

int ***r, **q, *p, i=8;

p = &i;

q = &p;

r = &q;

printf("%d, %d, %d\n", *p, **q, ***r);

return 0;

}

A. 8, 8, 8 B. 4000, 4002, 4004

C. 4000, 4004, 4008 D. 4000, 4008, 4016

Answer & Explanation

Answer: Option A

Explanation:

p is pointer to an integer so it contains addres of i

q is pointer to an integer pointer .so it conatins address of p

r is pointer to pointer to an integer pointer which stores address of q

Page 113: EXPRESSIONS - Google Groups

DURGA SOFTAWARE SOLUTIONS

CRT-C Language

DURGA SOFTWARE SOLUTIONS, 23/3RT, 2nd Floor. Opp: Reebok Shoe Room, Near Andhra Bank S.R Nagar, Hyderabad. Cell: 9246212143, Ph: 040-64512786 Page 113

8. What will be the output of the program ?

#include<stdio.h>

int main()

{

static char *s[] = {"black", "white", "pink", "violet"};

char **ptr[] = {s+3, s+2, s+1, s}, ***p;

p = ptr;

++p;

printf("%s", **p+1);

return 0;

}

A. ink B. ack

C. ite D. let

Answer & Explanation

Answer: Option A

Explanation:

s is array character pointer

s[0]=black and ptr[0]=violet

s[1]=white ptr[1]=pink

s[2]=pink ptr[2]=white

s[3]=violet ptr[3]=black

here p=ptr means p,ptr represents same address

++p means pointing to second element in the ptr array that is it contains the address of pink

**p+1 =>> here **p means pink addres and +1 means pointing to ink so the output is ink.

9.void main()

{

char *p;

printf("%d %d ",sizeof(*p),sizeof(p));

}

Answer:

1 2

A. 1 2 B. 1 1 C. 2 2 D. error

Explanation:

The sizeof() operator gives the number of bytes taken by its operand. P is a

character pointer, which needs one byte for storing its value (a character). Hence sizeof(*p)

gives a value of 1. Since it needs two bytes to store the address of the character pointer

Page 114: EXPRESSIONS - Google Groups

DURGA SOFTAWARE SOLUTIONS

CRT-C Language

DURGA SOFTWARE SOLUTIONS, 23/3RT, 2nd Floor. Opp: Reebok Shoe Room, Near Andhra Bank S.R Nagar, Hyderabad. Cell: 9246212143, Ph: 040-64512786 Page 114

sizeof(p) gives 2.

10. What will be the output of the program ?

#include<stdio.h>

int main()

{

char str[20] = "Hello";

char *const p=str;

*p='M';

printf("%s\n", str);

return 0;

}

A. Mello B. Hello

C. HMello D. MHello

Answer: Option A

Explanation:

Here p contains the base address.char *const p means p should not be modifed but *p can be

modified

So *p=ā€ŸMā€Ÿ means H sholud be replaced by M.so out put is Mello

11. What will be the output of the program ?

#include<stdio.h>

void fun(void *p);

int i=100;

int main()

{

void *vptr;

vptr = &i;

fun(vptr);

return 0;

}

void fun(void *p)

{

int **q;

q = (int**)&p;

printf("%d\n", **q);

}

A. Error: cannot convert from void** to int**

B. Garbage value

C. 100

Page 115: EXPRESSIONS - Google Groups

DURGA SOFTAWARE SOLUTIONS

CRT-C Language

DURGA SOFTWARE SOLUTIONS, 23/3RT, 2nd Floor. Opp: Reebok Shoe Room, Near Andhra Bank S.R Nagar, Hyderabad. Cell: 9246212143, Ph: 040-64512786 Page 115

D. 0

Answer: Option C

Explanation:

Here vptr contains the address of I after that,it is passed to function.the address of vptr(void **

type) is converted to (int**) and assigned to q. so **q will give the value of i that is 100

12. What will be the output of the program ?

#include<stdio.h>

int main()

{

char *str;

str = "%s";

printf(str, "K\n");

return 0;

}

A. Error B. No output

C. K D. %s

Answer & Explanation

Answer: Option C

Explanation:

Here the printf 1st arugment is replaced with ā€œ%sā€

Prinf(ā€œ%sā€,ā€K\nā€); that is how the compiler is treated.

So the output is K

13. What will be the output of the program?

#include<stdio.h>

int main()

{

int arr[2][2][2] = {10, 2, 3, 4, 5, 6, 7, 8};

int *p, *q;

p = &arr[1][1][1];

q = (int*) arr;

printf("%d, %d\n", *p, *q);

return 0;

}

[A]. 8, 10

[B]. 10, 2

[C]. 8, 1 [D]. Garbage values

Page 116: EXPRESSIONS - Google Groups

DURGA SOFTAWARE SOLUTIONS

CRT-C Language

DURGA SOFTWARE SOLUTIONS, 23/3RT, 2nd Floor. Opp: Reebok Shoe Room, Near Andhra Bank S.R Nagar, Hyderabad. Cell: 9246212143, Ph: 040-64512786 Page 116

Answer: Option A

Explanation:

arr[1][1][1]=8,

*p,

p=&arr[1][1][1],

*p means value at address i.e=8.

(int*)arr always gives first value addres ,

o/p= 8 10

14. The program wonā€Ÿt compile

void main()

{

clrscr();

}

clrscr();

A. Ture B.False

Answer:

B.false

No output/error

Explanation:

The first clrscr() occurs inside a function. So it becomes a function call. In the

second clrscr(); is a function declaration (because it is not inside any

function).

15. What will be the output of the program assuming that the array begins at the location 1002

and size of an integer is 4 bytes?

#include<stdio.h>

int main()

{

int a[3][4] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 };

printf("%u, %u, %u\n", a[0]+1, *(a[0]+1), *(*(a+0)+1));

return 0;

}

[A]. 448, 4, 4 [B]. 520, 2, 2

[C]. 1006, 2, 2

[D]. Error

Answer: Option C

Explanation:

Page 117: EXPRESSIONS - Google Groups

DURGA SOFTAWARE SOLUTIONS

CRT-C Language

DURGA SOFTWARE SOLUTIONS, 23/3RT, 2nd Floor. Opp: Reebok Shoe Room, Near Andhra Bank S.R Nagar, Hyderabad. Cell: 9246212143, Ph: 040-64512786 Page 117

The array begins at the location 1002 and each integer occupies 4bytes. a[0]+1 =(1002+1(is

nothing but 4 bytes)) = 1006

*(a[0]+1) means a[0][1] so 2

*(*(a+0)+1) means a[0][1] so 2

16.void main()

{

char *p;

p="Hello";

printf("%c\n",*&*p);

}

A. Hello B. H C. Garbage Value D.Error

Answer:

H

Explanation:

* is a dereference operator & is a reference operator. They can be applied

any number of times provided it is meaningful. Here p points to the first

character in the string "Hello". *p dereferences it and so its value is H. Again

& references it to an address and * dereferences it to the value H.

17. What will be the output of the program ?

#include<stdio.h>

int main()

{

char *str;

str = "%d\n";

str++;

str++;

printf(str-2, 3000);

return 0;

}

A. No output B. 30

C. 3 D. 3000

Answer & Explanation

Answer: Option D

Explanation:

str[0] str[1] str[2]

%d \n \0

Page 118: EXPRESSIONS - Google Groups

DURGA SOFTAWARE SOLUTIONS

CRT-C Language

DURGA SOFTWARE SOLUTIONS, 23/3RT, 2nd Floor. Opp: Reebok Shoe Room, Near Andhra Bank S.R Nagar, Hyderabad. Cell: 9246212143, Ph: 040-64512786 Page 118

500 501 502

Str contains 500

++str means 501

++str means 502

Str-2 menas 500

Printf(str-2,300)is treatd as printf(500 address,300)=>printf(ā€œ%d\nā€,3000);

So the output is 3000

18.void main()

{

int *j;

{

int i=10;

j=&i;

}

printf("%d",*j);

}

A. 0 B. 10 C. Garbage Value D.error

Answer:

10

Explanation:

The variable i is a block level variable and the visibility is inside that block

only. But the lifetime of i is lifetime of the function so it lives upto the exit of

main function. Since the i is still allocated space, *j prints the value stored in i

since j points i.

19.What will be the output of the program ?

#include<stdio.h>

int main()

{

printf("%c\n", 5["DurgaExams"]);

return 0;

}

A. Error: in printf B. Nothing will print

C. print "E" of DurgaExams D. print "5"

Answer & Explanation

Answer: Option C

Explanation:

a[i] can be written as i[a]

so 5["DurgaExams"] can be written as "DurgaExams"[5] that is value at 5th

index

Page 119: EXPRESSIONS - Google Groups

DURGA SOFTAWARE SOLUTIONS

CRT-C Language

DURGA SOFTWARE SOLUTIONS, 23/3RT, 2nd Floor. Opp: Reebok Shoe Room, Near Andhra Bank S.R Nagar, Hyderabad. Cell: 9246212143, Ph: 040-64512786 Page 119

20. Will the following code compile

void main()

{

char *cptr,c;

void *vptr,v;

c=10; v=0;

cptr=&c; vptr=&v;

printf("%c%v",c,v);

}

A. Yes B. No

Answer:

B. No

Compiler error (at line number 4): size of v is Unknown.

Explanation:

You can create a variable of type void * but not of type void, since void is an

empty type. In the second line you are creating variable vptr of type void * and

v of type void hence an error.

21.What will be the output of the program ?

#include<stdio.h>

int main()

{

char str[] = "peace wolrd";

char *s = str;

printf("%s\n", s++ +3);

return 0;

}

A. Peace wolrd B. Eace world

C. Ace world D. ce world

Answer & Explanation

Answer: Option D

Explanation:

S contains starting address of string so s++ +3 gives the addres from the thrid index so the

output is ce world

22.What will be the output of the program ?

#include<stdio.h>

int main()

Page 120: EXPRESSIONS - Google Groups

DURGA SOFTAWARE SOLUTIONS

CRT-C Language

DURGA SOFTWARE SOLUTIONS, 23/3RT, 2nd Floor. Opp: Reebok Shoe Room, Near Andhra Bank S.R Nagar, Hyderabad. Cell: 9246212143, Ph: 040-64512786 Page 120

{

char *p;

p="hell";

printf("%s\n", *&*&p);

return 0;

}

A. ll B. hell

C. ell D. h

Answer & Explanation

Answer: Option B

In printf * &*& will cancel out and it will be tread as printf(ā€œ%s\nā€,p)=>printf(ā€œ%s\nā€,ā€hellā€);

23.void main()

{

char *p;

int *q;

long *r;

p=q=r=0;

p++;

q++;

r++;

printf("%p...%p...%p",p,q,r);

}

A . 0001...0002...0004 B.0002ā€¦0002ā€¦.0002

C. 0001...0001...0001 D.0004...0004...0004

Answer:

A.0001...0002...0004

Explanation:

++ operator when applied to pointers increments address according to their

corresponding data-types.

24.What will be the output of the program ?

#include<stdio.h>

power(int**);

int main()

{

int a=6, *aa; /* Address od 'a' is 1000 */

aa = &a;

a = power(&aa);

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

return 0;

Page 121: EXPRESSIONS - Google Groups

DURGA SOFTAWARE SOLUTIONS

CRT-C Language

DURGA SOFTWARE SOLUTIONS, 23/3RT, 2nd Floor. Opp: Reebok Shoe Room, Near Andhra Bank S.R Nagar, Hyderabad. Cell: 9246212143, Ph: 040-64512786 Page 121

}

power(int **ptr)

{

int b;

b = **ptr***ptr;

return (b);

}

A. 6 B. 36

C. 216 D. Garbage value

Answer & Explanation

Answer: Option B

Explanation:

aa = &a; // *aa = 6;

power(&aa) is of int** type

**ptr = &aa; ptr is a pointer to a pointer aa.

Hence value stored in a can be accessed using **ptr(which is **ptr = 6).

So the b = **ptr ***ptr means b = 6*6which is 36.

25. What will be the output of the program ?

#include<stdio.h>

int main()

{

int i, a[] = {2, 4, 6, 8, 10};

change(a, 5);

for(i=0; i<=4; i++)

printf("%d, ", a[i]);

return 0;

}

change(int *b, int n)

{

int i;

for(i=0; i<n; i++)

*(b+i) = *(b+i)+5;

}

[A]. 7, 9, 11, 13, 15 [B]. 2, 15, 6, 8, 10

[C]. 2 4 6 8 10 [D]. 3, 1, -1, -3, -5

Answer: Option A

Page 122: EXPRESSIONS - Google Groups

DURGA SOFTAWARE SOLUTIONS

CRT-C Language

DURGA SOFTWARE SOLUTIONS, 23/3RT, 2nd Floor. Opp: Reebok Shoe Room, Near Andhra Bank S.R Nagar, Hyderabad. Cell: 9246212143, Ph: 040-64512786 Page 122

Explanation:

*(b+i) = *(b+i)+5;

1. i = 0 => *(b+1) ie 4 is replaced by *(b+0)+5 ie 2+5

2. i = 1 => *(b+1) ie 4 is replaced by *(b+1)+5 ie 4+5

3. i = 2 => *(b+1) ie 4 is replaced by *(b+2)+5 ie 6+5

4. i = 3 => *(b+1) ie 4 is replaced by *(b+3)+5 ie 8+5

5. i = 4 => *(b+1) ie 4 is replaced by *(b+4)+5 ie 10+5

26. Point out the error in the program

#include<stdio.h>

int main()

{

int a[] = {1, 2, 3, 4, 5};

int j;

for(j=0; j<5; j++)

{

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

a++;

}

return 0;

}

A. Error: Declaration syntax B. Error: Expression syntax

C. Error: LValue required D. Error: Rvalue required

Answer & Explanation

Answer: Option C

Explanation:

The error at statement a++ a is the array name treated as constatn pointer which should

not be modifed

27. Which of the following statements correctly declare a function that receives a pointer to

pointer to a pointer to a float and returns a pointer to a pointer to a pointer to a pointer to a float?

[A]. float **fun(float***); [B]. float *fun(float**);

[C]. float fun(float***); [D]. float ****fun(float***);

Answer: Option D

Explanation:

Page 123: EXPRESSIONS - Google Groups

DURGA SOFTAWARE SOLUTIONS

CRT-C Language

DURGA SOFTWARE SOLUTIONS, 23/3RT, 2nd Floor. Opp: Reebok Shoe Room, Near Andhra Bank S.R Nagar, Hyderabad. Cell: 9246212143, Ph: 040-64512786 Page 123

From the given question,

"... receives a pointer to pointer to a pointer to a float ***

"... returns a pointer to a pointer to a pointer to a pointer...so the return type is float ****

Therefore, float ****fun (float ***) is the correct answer.

28. Which of the statements is correct about the program?

#include<stdio.h>

int main()

{

int i=10;

int *j=&i;

return 0;

}

A. j and i are pointers to an int

B. i is a pointer to an int and stores address of j

C. j is a pointer to an int and stores address of i

D. j is a pointer to a pointer to an int and stores address of i

Answer & Explanation

Answer: Option C

29. In the following program add a statement in the function fun() such that address of a gets

stored in j?

#include<stdio.h>

int main()

{

int *j;

void fun(int**);

fun(&j);

return 0;

}

void fun(int **k)

{

int a=10;

/* Add a statement here */

}

A. **k=a; B. k=&a;

C. *k=&a D. &k=*a

Page 124: EXPRESSIONS - Google Groups

DURGA SOFTAWARE SOLUTIONS

CRT-C Language

DURGA SOFTWARE SOLUTIONS, 23/3RT, 2nd Floor. Opp: Reebok Shoe Room, Near Andhra Bank S.R Nagar, Hyderabad. Cell: 9246212143, Ph: 040-64512786 Page 124

Answer & Explanation

Answer: Option C

Explanation:

Here in the function call k conatins address of j

Where k is of int ** and contains jā€Ÿs address so any modification done on k will be effected on j.

Inorder to get aā€Ÿs address in j

Add *k=&a

Where *k int of int *type and &a is also int * type

30. Which of the statements is correct about the program?

#include<stdio.h>

int main()

{

int arr[3][3] = {1, 2, 3, 4};

printf("%d\n", *(*(*(arr))));

return 0;

}

A. Output: Garbage value B. Output: 1

C. Output: 3 D. Error: Invalid indirection

Answer & Explanation

Answer: Option D

Explanation:

Here arr is 2D array so at max we can go for pointer to pointer.

Here it is asked to print value at pointer to pointer to pointer

31. Which statement will you add to the following program to ensure that the program outputs

"Durga Exams" on execution?

#include<stdio.h>

int main()

{

char s[] = " Durga Exams ";

char t[25];

char *ps, *pt;

ps = s;

pt = t;

while(*ps)

Page 125: EXPRESSIONS - Google Groups

DURGA SOFTAWARE SOLUTIONS

CRT-C Language

DURGA SOFTWARE SOLUTIONS, 23/3RT, 2nd Floor. Opp: Reebok Shoe Room, Near Andhra Bank S.R Nagar, Hyderabad. Cell: 9246212143, Ph: 040-64512786 Page 125

*pt++ = *ps++;

/* Add a statement here */

printf("%s\n", t);

return 0;

}

A. *pt=''; B. pt='\0';

C. pt='\n'; D. *pt='\0';

Answer & Explanation

Answer: Option D

Explanation:

In the loop the data is copied by character by character basis so null character is not copied so,

after the loop terminates t conations only Durga Exams so explicitly null character should be

appended.

36. Are the expression *ptr++ and ++*ptr are same?

A. True B. False

Answer & Explanation

Answer: Option B

Explanation:

*ptr++ increments the pointer and not the value, whereas the ++*ptr increments the value being

pointed by ptr

37. The program will compile?

#include<stdio.h>

int main()

{

char s[5] = "Durga Exams";

return 0;

}

A. True B. False

Answer & Explanation

Page 126: EXPRESSIONS - Google Groups

DURGA SOFTAWARE SOLUTIONS

CRT-C Language

DURGA SOFTWARE SOLUTIONS, 23/3RT, 2nd Floor. Opp: Reebok Shoe Room, Near Andhra Bank S.R Nagar, Hyderabad. Cell: 9246212143, Ph: 040-64512786 Page 126

Answer: Option B

Explanation:

C doesn't do array bounds checking at compile time, hence this compiles.

But, the modern compilers like Turbo C++ detects this as 'Error: Too many initializers'.

GCC would give you a warning.

38. The following program reports an error on compilation.

#include<stdio.h>

int main()

{

float i=100, *j;

void *k;

k=&i;

j=k;

printf("%f\n", *j);

return 0;

}

A. True B. False

Answer & Explanation

Answer: Option B

Explanation:

This program will NOT report any error. (Tested in Turbo C under DOS and GCC under Linux)

The output: 100.000000

39. Are the three declarations char **a, char *a[], and char a[][] same?

A. True B. False

Answer & Explanation

Answer: Option B

Explanation:

char **a is pointer to pointer to character

Page 127: EXPRESSIONS - Google Groups

DURGA SOFTAWARE SOLUTIONS

CRT-C Language

DURGA SOFTWARE SOLUTIONS, 23/3RT, 2nd Floor. Opp: Reebok Shoe Room, Near Andhra Bank S.R Nagar, Hyderabad. Cell: 9246212143, Ph: 040-64512786 Page 127

char *a[] is array of character pointer

char a[][] is 2D character array.

40. Is there any difference between the following two statements?

char *a=0;

char *b=NULL

A. Yes B. No

Answer & Explanation

Answer: Option B

Explanation:

NULL is #defined as 0 in the 'stdio.h' file. Thus, both a and b are NULL pointers

41. Is the NULL pointer same as an uninitialised pointer?

A. Yes B. No

Answer: Option B

Explanation:

A Null pointer is one which holds 0 (zero) as its value and uninitialized pointer may have some

garbage value.

Page 128: EXPRESSIONS - Google Groups

DURGA SOFTAWARE SOLUTIONS

CRT-C Language

DURGA SOFTWARE SOLUTIONS, 23/3RT, 2nd Floor. Opp: Reebok Shoe Room, Near Andhra Bank S.R Nagar, Hyderabad. Cell: 9246212143, Ph: 040-64512786 Page 128

Arrays 1.void main()

{

int c[ ]={2.8,3.4,4,6.7,5};

int j,*p=c,*q=c;

for(j=0;j<5;j++) {

printf(" %d ",*c);

++q; }

for(j=0;j<5;j++){

printf(" %d ",*p);

++p; }

}

Answer:

2 2 2 2 2 2 3 4 6 5

A. 2 3 4 6 5 5 5 5 5 5 B. 2 2 2 2 2 2 3 4 6 5 C. garbage value D. error

Explanation:

Initially pointer c is assigned to both p and q. In the first loop, since only q is

incremented and not c , the value 2 will be printed 5 times. In second loop p itself is

incremented. So the values 2 3 4 6 5 will be printed.

2.What does the following declaration mean?

int (*ptr)[10]

A. ptr is array of pointers to 10 integers

B. ptr is a pointer to an array of 10 integers

C. ptr is an array of 10 integers

D. ptr is an pointer to array

Answer & Explanation

Answer: Option B

Explanation:

If its is written as int *ptr[10] then it is treated as array of 10 pointer

3. In C, if you pass an array as an argument to a function, what actually gets passed?

A. Value of elements in array

B. First element of the array

C. Base address of the array

D. Address of the last element of array

Page 129: EXPRESSIONS - Google Groups

DURGA SOFTAWARE SOLUTIONS

CRT-C Language

DURGA SOFTWARE SOLUTIONS, 23/3RT, 2nd Floor. Opp: Reebok Shoe Room, Near Andhra Bank S.R Nagar, Hyderabad. Cell: 9246212143, Ph: 040-64512786 Page 129

Answer & Explanation

Answer: Option C

Explanation:

The statement 'C' is correct. When we pass an array as a funtion argument, the base address of

the array will be passed.

Eg:

int fun(int*);

void main()

{

int a[5];

fun(a);//here it base addres of the array.

}

int fun(int *p1)

{

}

4. #include<stdio.h>

void main()

{

int a[2][2][2] = { {10,2,3,4}, {5,6,7,8} };

int *p,*q;

p=&a[2][2][2];

*q=***a;

printf("%d----%d",*p,*q);

}

Answer:

SomeGarbageValue---1

A. 10 1 B. garbage value - -1 C. 10 5 D. Error

Explanation:

p=&a[2][2][2] you declare only two 2D arrays, but you are trying to access the

third 2D(which you are not declared) it will print garbage values. *q=***a starting address of

a is assigned integer pointer. Now q is pointing to starting address of a. If you print *q, it will

print first element of 3D array.

6. What will happen if in a C program you assign a value to an array element whose subscript

exceeds the size of array?

A. The element will be set to 0.

B. The compiler would report an error.

Page 130: EXPRESSIONS - Google Groups

DURGA SOFTAWARE SOLUTIONS

CRT-C Language

DURGA SOFTWARE SOLUTIONS, 23/3RT, 2nd Floor. Opp: Reebok Shoe Room, Near Andhra Bank S.R Nagar, Hyderabad. Cell: 9246212143, Ph: 040-64512786 Page 130

C. The program may crash if some important data gets overwritten.

D. The array size would appropriately grow.

Answer & Explanation

Answer: Option C

Explanation:

If the index of the array size is exceeded, the program will crash. Hence "option c" is the correct

answer.

Example: Run the below program, it will crash in Windows (TurboC Compiler)

#include<stdio.h>

int main()

{

int arr[10];

arr[100]=100;

printf("%d",arr[100]);

return 0;

}

In C there is no bounadary checking Since C is a compiler dependent language, it may give

different outputs at different platforms. We have given the Turbo-C Compiler (Windows) output.

Please try the above programs in Windows (Turbo-C Compiler) and Linux (GCC Compiler), you

will understand the difference better.

7. void main( )

{

int a[2][3][2] = {{{2,4},{7,8},{3,4}},{{2,2},{2,3},{3,4}}};//base address is 100

printf(ā€œ%u %u %u %d \nā€,a,*a,**a,***a);

printf(ā€œ%u %u %u %d \nā€,a+1,*a+1,**a+1,***a+1);

}

Answer:

100, 100, 100, 2

114, 104, 102, 3

Explanation:

The given array is a 3-D one. It can also be viewed as a 1-D array.

2 4 7 8 3 4 2 2 2 3 3 4

100 102 104 106 108 110 112 114 116 118 120 122

thus, for the first printf statement a, *a, **a give address of first element .

since the indirection ***a gives the value. Hence, the first line of the output.

Page 131: EXPRESSIONS - Google Groups

DURGA SOFTAWARE SOLUTIONS

CRT-C Language

DURGA SOFTWARE SOLUTIONS, 23/3RT, 2nd Floor. Opp: Reebok Shoe Room, Near Andhra Bank S.R Nagar, Hyderabad. Cell: 9246212143, Ph: 040-64512786 Page 131

for the second printf a+1 increases in the third dimension thus points to value at 114, *a+1

increments in second dimension thus points to 104, **a +1 increments the first dimension thus

points to 102 and ***a+1 first gets the value at first location and then increments it by 1. Hence,

the output.

8.void main( )

{

int a[ ] = {10,20,30,40,50},j,*p;

for(j=0; j<5; j++)

{

printf(ā€œ%dā€ ,*a);

a++;

}

p = a;

for(j=0; j<5; j++)

{

printf(ā€œ%d ā€ ,*p);

p++;

}

}

A 10 20 30 40 50 10 20 30 40 50 B 10 20 30 40 50 C Error

D. None of the above.

Answer:

Compiler error: lvalue required.

Explanation:

Error is in line with statement a++. The operand must be an lvalue and may

be of any of scalar type for the any operator, array name only when

subscripted is an lvalue. Simply array name is a non-modifiable lvalue.

9.void main( )

{

static int a[ ] = {0,1,2,3,4};

int *p[ ] = {a,a+1,a+2,a+3,a+4};

int **ptr = p;

ptr++;

printf(ā€œ\n %d %d %dā€, ptr-p, *ptr-a, **ptr);

*ptr++;

printf(ā€œ\n %d %d %dā€, ptr-p, *ptr-a, **ptr);

*++ptr;

printf(ā€œ\n %d %d %dā€, ptr-p, *ptr-a, **ptr);

++*ptr;

printf(ā€œ\n %d %d %dā€, ptr-p, *ptr-a, **ptr);

}

Answer:

111

Page 132: EXPRESSIONS - Google Groups

DURGA SOFTAWARE SOLUTIONS

CRT-C Language

DURGA SOFTWARE SOLUTIONS, 23/3RT, 2nd Floor. Opp: Reebok Shoe Room, Near Andhra Bank S.R Nagar, Hyderabad. Cell: 9246212143, Ph: 040-64512786 Page 132

222

333

344

Explanation:

Let us consider the array and the two pointers with some address

a

0 1 2 3 4

100 102 104 106 108

p

100 102 104 106 108

1000 1002 1004 1006 1008

ptr

1000

2000

After execution of the instruction ptr++ value in ptr becomes 1002, if scaling

factor for integer is 2 bytes. Now ptr ā€“ p is value in ptr ā€“ starting location of

array p, (1002 ā€“ 1000) / (scaling factor) = 1, *ptr ā€“ a = value at address

pointed by ptr ā€“ starting value of array a, 1002 has a value 102 so the value

is (102 ā€“ 100)/(scaling factor) = 1, **ptr is the value stored in the location

pointed by the pointer of ptr = value pointed by value pointed by 1002 = value

pointed by 102 = 1. Hence the output of the firs printf is 1, 1, 1.

After execution of *ptr++ increments value of the value in ptr by scaling factor,

so it becomes1004. Hence, the outputs for the second printf are ptr ā€“ p = 2,

*ptr ā€“ a = 2, **ptr = 2.

After execution of *++ptr increments value of the value in ptr by scaling factor,

so it becomes1004. Hence, the outputs for the third printf are ptr ā€“ p = 3, *ptr

ā€“ a = 3, **ptr = 3.

After execution of ++*ptr value in ptr remains the same, the value pointed by

the value is incremented by the scaling factor. So the value in array p at

location 1006 changes from 106 10 108,. Hence, the outputs for the fourth

printf are ptr ā€“ p = 1006 ā€“ 1000 = 3, *ptr ā€“ a = 108 ā€“ 100 = 4, **ptr = 4.

10. What will be the output of the program ?

#include<stdio.h>

int main()

{

int a[5] = {5, 1, 15, 20, 25};

int i, j, m;

i = ++a[1];

j = a[1]++;

m = a[i++];

printf("%d, %d, %d", i, j, m);

return 0;

}

A. 2, 1, 15 B. 1, 2, 5

Page 133: EXPRESSIONS - Google Groups

DURGA SOFTAWARE SOLUTIONS

CRT-C Language

DURGA SOFTWARE SOLUTIONS, 23/3RT, 2nd Floor. Opp: Reebok Shoe Room, Near Andhra Bank S.R Nagar, Hyderabad. Cell: 9246212143, Ph: 040-64512786 Page 133

C. 3, 2, 15 D. 2, 3, 20

Answer & Explanation

Answer: Option C

Explanation:

Step 1: int a[5] = {5, 1, 15, 20, 25}; The variable arr is declared as an integer array with a size of

5 and it is initialized to

a[0] = 5, a[1] = 1, a[2] = 15, a[3] = 20, a[4] = 25 .

Step 2: int i, j, m; The variable i,j,m are declared as an integer type.

Step 3: i = ++a[1]; becomes i = ++1; Hence i = 2 and a[1] = 2

Step 4: j = a[1]++; becomes j = 2++; Hence j = 2 and a[1] = 3.

Step 5: m = a[i++]; becomes m = a[2]; Hence m = 15 and i is incremented by 1(i++ means 2++

so i=3)

Step 6: printf("%d, %d, %d", i, j, m); It prints the value of the variables i, j, m

Hence the output of the program is 3, 2, 15

11 void main()

{

char name[10],s[12];

scanf(" \"%[^\"]\"",s);

}

How scanf will execute?

Answer:

First it checks for the leading white space and discards it.Then it matches with

a quotation mark and then it reads all character upto another quotation mark.

12. What will be the output of the program if the array begins at 65486 and each integer occupies

2 bytes?

#include<stdio.h>

int main()

{

int arr[] = {12, 14, 15, 23, 45};

printf("%u, %u\n", arr+1, &arr+1);

return 0;

}

A. 65488, 65490 B. 64490, 65492

C. 65488, 65496 D. 64490, 65498

Answer & Explanation

Answer: Option C

Page 134: EXPRESSIONS - Google Groups

DURGA SOFTAWARE SOLUTIONS

CRT-C Language

DURGA SOFTWARE SOLUTIONS, 23/3RT, 2nd Floor. Opp: Reebok Shoe Room, Near Andhra Bank S.R Nagar, Hyderabad. Cell: 9246212143, Ph: 040-64512786 Page 134

Explanation:

Step 1: int arr[] = {12, 14, 15, 23, 45}; The variable arr is declared as an integer array and

initialized.

Step 2: printf("%u, %u\n", arr+1, &arr+1);

Here, the base address(also the address of first element) of the array is 65486.

=> Here, arr is reference to arr has type "pointer to int". Therefore, arr+1 is pointing to second

element of the array arr memory location. Hence 65486 + 2 bytes = 65488

=> Then, &arr is "pointer to array of 5 ints". Therefore, &arr+1 denotes "5 ints * 2 bytes * 1 = 10

bytes".

Hence, begining address 65486 + 10 = 65496. So, &arr+1 = 65496

Hence the output of the program is 65486, 65496

13. #include<stdio.h>

void main()

{

int a[2][2][2] = { {10,2,3,4}, {5,6,7,8} };

int *p,*q;

p=&a[2][2][2];

*q=***a;

printf("%d..%d",*p,*q);

}

Answer:

garbagevalue..1

Explanation:

p=&a[2][2][2] you declare only two 2D arrays. but you are trying to access the third 2D(which

you are not declared) it will print garbage values. *q=***a starting address of a is assigned

integer pointer. now q is pointing to starting address of a.if you print *q meAnswer:it will print

first element of 3D array.

14. What will be the output of the program ?

#include<stdio.h>

int main()

{

static int a[2][2] = {1, 2, 3, 4};

int i, j;

static int *p[] = {(int*)a, (int*)a+1, (int*)a+2};

for(i=0; i<2; i++)

{

for(j=0; j<2; j++)

{

printf("%d, %d, %d, %d\n", *(*(p+i)+j), *(*(j+p)+i),

*(*(i+p)+j), *(*(p+j)+i));

}

}

Page 135: EXPRESSIONS - Google Groups

DURGA SOFTAWARE SOLUTIONS

CRT-C Language

DURGA SOFTWARE SOLUTIONS, 23/3RT, 2nd Floor. Opp: Reebok Shoe Room, Near Andhra Bank S.R Nagar, Hyderabad. Cell: 9246212143, Ph: 040-64512786 Page 135

return 0;

}

A.

1, 1, 1, 1

2, 3, 2, 3

3, 2, 3, 2

4, 4, 4, 4

B.

1, 2, 1, 2

2, 3, 2, 3

3, 4, 3, 4

4, 2, 4, 2

C.

1, 1, 1, 1

2, 2, 2, 2

2, 2, 2, 2

3, 3, 3, 3

D.

1, 2, 3, 4

2, 3, 4, 1

3, 4, 1, 2

4, 1, 2, 3

Answer: Option C

Explanation: step1: p[3]={a,a+1,a+2}

step2:i=0,j=0

*(*(p+i)+j)=a[0]=1

*(*(j+p)+i)=a[0]=1

*(*(i+p)+j)=a[0]=1

*(*(p+j)+i)=a[0]=1

step2:i=0,j=1

*(*(p+i)+j)=a[1]=2

*(*(j+p)+i)=a[1]=2

*(*(i+p)+j)=a[1]=2

*(*(p+j)+i)=a[1]=2

step3:i=1,j=0

*(*(p+i)+j)=a[1]=2

*(*(j+p)+i)=a[1]=2

*(*(i+p)+j)=a[1]=2

*(*(p+j)+i)=a[1]=2

step4:i=1,j=1

*(*(p+i)+j)=a[2]=3

*(*(j+p)+i)=a[2]=3

*(*(i+p)+j)=a[2]=3

*(*(p+j)+i)=a[2]=3

15. What will be the output of the program ?

#include<stdio.h>

int main()

{

static int arr[] = {0, 1, 2, 3, 4};

int *p[] = {arr, arr+1, arr+2, arr+3, arr+4};

int **ptr=p;

Page 136: EXPRESSIONS - Google Groups

DURGA SOFTAWARE SOLUTIONS

CRT-C Language

DURGA SOFTWARE SOLUTIONS, 23/3RT, 2nd Floor. Opp: Reebok Shoe Room, Near Andhra Bank S.R Nagar, Hyderabad. Cell: 9246212143, Ph: 040-64512786 Page 136

ptr++;

printf("%d, %d, %d\n", ptr-p, *ptr-arr, **ptr);

*ptr++;

printf("%d, %d, %d\n", ptr-p, *ptr-arr, **ptr);

*++ptr;

printf("%d, %d, %d\n", ptr-p, *ptr-arr, **ptr);

++*ptr;

printf("%d, %d, %d\n", ptr-p, *ptr-arr, **ptr);

return 0;

}

A.

0, 0, 0

1, 1, 1

2, 2, 2

3, 3, 3

B.

1, 1, 2

2, 2, 3

3, 3, 4

4, 4, 1

C.

1, 1, 1

2, 2, 2

3, 3, 3

3, 4, 4

D.

0, 1, 2

1, 2, 3

2, 3, 4

3, 4, 5

Answer & Explanation

Answer: Option C

16. What will be the output of the program ?

#include<stdio.h>

int main()

{

int arr[1]={100};

printf("%d\n", 0[arr]);

return 0;

}

A. 1 B. 100

C. 0 D. 6

Answer & Explanation

Answer: Option B

Explanation:

Step 1: int arr[1]={100}; The variable arr[1] is declared as an integer array with size '2' and it's

first element is initialized to value '10'(means arr[0]=100)

Step 2: printf("%d\n", 0[arr]); It prints the first element value of the variable arr.

Page 137: EXPRESSIONS - Google Groups

DURGA SOFTAWARE SOLUTIONS

CRT-C Language

DURGA SOFTWARE SOLUTIONS, 23/3RT, 2nd Floor. Opp: Reebok Shoe Room, Near Andhra Bank S.R Nagar, Hyderabad. Cell: 9246212143, Ph: 040-64512786 Page 137

Hence the output of the program is 100.

17. What will be the output of the program?

#include<stdio.h>

int main()

{

float arr[] = {1.4, 0.3, 4.50, 6.70};

printf("%d\n", sizeof(arr)/sizeof(arr[0]));

return 0;

}

A. 5 B. 4

C. 6 D. 7

Answer & Explanation

Answer: Option B

Explanation: The sizeof function return the given variable. Example: float a=10; sizeof(a) is 4 bytes

Step 1: float arr[] = {2.4, 0.3, 4.50, 6.70}; The variable arr is declared as an floating point array

and it is initialized with the values.

Step 2: printf("%d\n", sizeof(arr)/sizeof(arr[0]));

The variable arr has 4 elements. The size of the float variable is 4 bytes.

Hence 4 elements x 4 bytes = 16 bytes

sizeof(arr[0]) is 4 bytes

Hence 16/4 is 4 bytes

Hence the output of the program is '4'.

18. What will be the output of the program if the array begins 1200 in memory?

#include<stdio.h>

int main()

{

int a[]={2, 3, 4, 1, 6};

printf("%u, %u, %u\n", a, &a[0], &a);

return 0;

}

A. 1200, 1202, 1204 B. 1200, 1200, 1200

C. 1200, 1204, 1208 D. 1200, 1202, 1200

Answer & Explanation

Answer: Option B

Explanation:

Page 138: EXPRESSIONS - Google Groups

DURGA SOFTAWARE SOLUTIONS

CRT-C Language

DURGA SOFTWARE SOLUTIONS, 23/3RT, 2nd Floor. Opp: Reebok Shoe Room, Near Andhra Bank S.R Nagar, Hyderabad. Cell: 9246212143, Ph: 040-64512786 Page 138

Step 1: int a[]={2, 3, 4, 1, 6}; The variable a is declared as an integer array and initialized.

Step 2: printf("%u, %u, %u\n", a, &a[0], &a); Here,

The base address of the array is 1200.

=> a, &a is pointing to the base address of the array a.

=> &a[0] is pointing to the address of the first element array a. (ie. base address)

Hence the output of the program is 1200, 1200, 1200

19. What will be the output of the program if the array begins at address 65486?

#include<stdio.h>

int main()

{

int a[] = {1, 2, 3, 4, 5};

printf("%u, %u\n", a, &a);

return 0;

}

A. 65486, 65488 B. 65486, 65486

C. 65486, 65490 D. 65486, 65487

Answer & Explanation

Answer: Option B

Explanation: Step 1: int a[] = {12, 14, 15, 23, 45}; The variable a is declared as an integer array and

initialized.

Step 2: printf("%u, %u\n", a, a); Here,

The base address of the array is 65486.

=> a, &a is pointing to the base address of the array a.

Hence the output of the program is 65486, 65486

20. Which of the following is correct way to define the function fun() in the below program?

#include<stdio.h>

int main()

{

int a[3][4];

fun(a);

return 0;

}

[A].

void fun(int p[][4])

{

}

[B].

void fun(int *p[4])

{

}

[C].

void fun(int *p[][4])

{

} [D].

void fun(int *p[3][4])

{

}

Answer: Option A

Page 139: EXPRESSIONS - Google Groups

DURGA SOFTAWARE SOLUTIONS

CRT-C Language

DURGA SOFTWARE SOLUTIONS, 23/3RT, 2nd Floor. Opp: Reebok Shoe Room, Near Andhra Bank S.R Nagar, Hyderabad. Cell: 9246212143, Ph: 040-64512786 Page 139

Explanation:

void fun(int p[][4]){ } is the correct way to write the function fun(). while the others are

considered only the function fun() is called by using call by reference.

21. Which of the following statements are correct about the program below?

#include<stdio.h>

int main()

{

int size, i;

scanf("%d", &size);

int arr[size];

for(i=1; i<=size; i++)

{

scanf("%d", arr[i]);

printf("%d", arr[i]);

}

return 0;

}

A. The code is erroneous since the subscript for array used in for loop is in the range 1 to size.

B. The code is erroneous since the values of array are getting scanned through the loop.

C. The code is erroneous since the statement declaring array is invalid.

D. The code is correct and runs successfully.

Answer & Explanation

Answer: Option C

Explanation:

The statement int arr[size]; produces an error, because we cannot initialize the size of array

dynamically. Constant expression is required here.

Example: int arr[10];

One more point is there, that is, usually declaration is not allowed after calling any function in a

current block of code. In the given program the declaration int arr[10]; is placed after a function

call scanf().

22. Which of the following statements are correct about 6 used in the program?

int num[6];

num[6]=21;

Page 140: EXPRESSIONS - Google Groups

DURGA SOFTAWARE SOLUTIONS

CRT-C Language

DURGA SOFTWARE SOLUTIONS, 23/3RT, 2nd Floor. Opp: Reebok Shoe Room, Near Andhra Bank S.R Nagar, Hyderabad. Cell: 9246212143, Ph: 040-64512786 Page 140

A.

In the first statement 6 specifies a particular element, whereas in the second statement it

specifies a type.

B.

In the first statement 6 specifies a array size, whereas in the second statement it specifies a

particular element of array.

C.

In the first statement 6 specifies a particular element, whereas in the second statement it

specifies a array size.

D. In both the statement 6 specifies array size.

Answer & Explanation

Answer: Option B

Explanation:

The statement 'B' is correct, because int num[6]; specifies the size of array and num[6]=21;

designates the particular element(7th

element) of the array.

23. Which of the following statements are correct about an array?

1: The array int num[26]; can store 26 elements.

2: The expression num[1] designates the very first element in the array.

3: It is necessary to initialize the array at the time of declaration.

4: The declaration num[SIZE] is allowed if SIZE is a macro.

A. 1 B. 1,4

C. 2,3 D. 2,4

Answer & Explanation

Answer: Option B

Explanation:

1. The array int num[26]; can store 26 elements. This statement is true.

2. The expression num[1] designates the very first element in the array. This statement is false,

because it designates the second element of the array.

3. It is necessary to initialize the array at the time of declaration. This statement is false.

4. The declaration num[SIZE] is allowed if SIZE is a macro. This statement is true, because the

MACRO just replaces the symbol SIZE with given value.

Hence the statements '1' and '4' are correct statements.

24. A pointer to a block of memory is effectively same as an array

A. True B. False

Answer & Explanation

Page 141: EXPRESSIONS - Google Groups

DURGA SOFTAWARE SOLUTIONS

CRT-C Language

DURGA SOFTWARE SOLUTIONS, 23/3RT, 2nd Floor. Opp: Reebok Shoe Room, Near Andhra Bank S.R Nagar, Hyderabad. Cell: 9246212143, Ph: 040-64512786 Page 141

Answer: Option A

Explanation:

Yes, It is possible to allocate a block of memory (of arbitrary size) at run-time, using the

standard library's malloc or calloc or reaclloc function, and treat it as an array.

25. Does this mentioning array name gives the base address in all the contexts?

A. Yes B. No

Answer & Explanation

Answer: Option B

Explanation:

No, Mentioning the array name in C or C++ gives the base address in all contexts except one.

Syntactically, the compiler treats the array name as a pointer to the first element. You can

reference elements using array syntax, a[n], or using pointer syntax, *(a+n), and you can even

mix the usages within an expression.

When you pass an array name as a function argument, you are passing the "value of the pointer",

which means that you are implicitly passing the array by reference, even though all parameters in

functions are "call by value".

26. Is there any difference int the following declarations?

int f1(int arr[]);

int f1(int arr[100]);

A. Yes B. No

Answer & Explanation

Answer: Option B

Explanation:

No, both the statements are same. It is the prototype for the function f1() that accepts one integer

array as an parameter and returns an integer value.

27. Are the expressions arr and &arr same for an array of 10 integers?

A. Yes B. No

Page 142: EXPRESSIONS - Google Groups

DURGA SOFTAWARE SOLUTIONS

CRT-C Language

DURGA SOFTWARE SOLUTIONS, 23/3RT, 2nd Floor. Opp: Reebok Shoe Room, Near Andhra Bank S.R Nagar, Hyderabad. Cell: 9246212143, Ph: 040-64512786 Page 142

Answer & Explanation

Answer: Option B

Explanation:

Both mean two different things. arr gives the address of the first int, whereas the &arr gives the

address of array of ints.

Page 143: EXPRESSIONS - Google Groups

DURGA SOFTAWARE SOLUTIONS

CRT-C Language

DURGA SOFTWARE SOLUTIONS, 23/3RT, 2nd Floor. Opp: Reebok Shoe Room, Near Andhra Bank S.R Nagar, Hyderabad. Cell: 9246212143, Ph: 040-64512786 Page 143

Strings

1. How will you print \n on the screen?

A. printf("\n"); B. echo "\\n";

C. printf('\n'); D. printf("\\n");

Answer & Explanation

Answer: Option D

Explanation:

The statement printf("\\n"); prints '\n' on the screen.

2. The library function used to reverse a string is

A. strstr() B. strrev()

C. revstr() D. strreverse()

Answer & Explanation

Answer: Option B

Explanation:

strrev(s) Reverses all characters in s

3. Which of the following function sets first n characters of a string to a given character?

A. strinit() B. strnset()

C. strset() D. strcset()

Answer & Explanation

Answer: Option B

Explanation:

Declaration:

char *strnset(char *s, int ch, size_t n); Sets the first n characters of s to ch

Page 144: EXPRESSIONS - Google Groups

DURGA SOFTAWARE SOLUTIONS

CRT-C Language

DURGA SOFTWARE SOLUTIONS, 23/3RT, 2nd Floor. Opp: Reebok Shoe Room, Near Andhra Bank S.R Nagar, Hyderabad. Cell: 9246212143, Ph: 040-64512786 Page 144

4. #include <stdio.h>

#include <string.h>

int main(void)

{

char *string = "abcdefghijklmnopqrstuvwxyz";

char letter = 'x';

printf("string before strnset: %s\n", string);

strnset(string, letter, 13);

printf("string after strnset: %s\n", string);

return 0;

}

Output:

string before strnset: abcdefghijklmnopqrstuvwxyz

string after strnset: xxxxxxxxxxxxxnopqrstuvwxyz

5.void main()

{

char s[ ]="man";

int i;

for(i=0;s[ i ];i++)

printf("\n%c%c%c%c",s[ i ],*(s+i),*(i+s),i[s]);

}

A.man

man

man

man

B. mmmm

aaaa

nnnn

C. Error

D. None of the above

Answer:

mmmm

aaaa

nnnn

Explanation:

s[i], *(i+s), *(s+i), i[s] are all different ways of expressing the same idea.

Generally array name is the base address for that array. Here s is the base address. i is the

index number/displacement from the base address. So, indirecting it with * is same as s[i].

i[s] may be surprising. But in the case of C it is same as s[i].

Page 145: EXPRESSIONS - Google Groups

DURGA SOFTAWARE SOLUTIONS

CRT-C Language

DURGA SOFTWARE SOLUTIONS, 23/3RT, 2nd Floor. Opp: Reebok Shoe Room, Near Andhra Bank S.R Nagar, Hyderabad. Cell: 9246212143, Ph: 040-64512786 Page 145

6.void main()

{

char string[]="Hello World";

display(string);

}

void display(char *string)

{

printf("%s",string);

}

Answer:

Compiler Error : Type mismatch in redeclaration of function display

A. Hello World B. Compiler Error C. H D. None of the above

Explanation :

In third line, when the function display is encountered, the compiler doesn't

know anything about the function display. It assumes the arguments and return types to be

integers, (which is the default type). When it sees the actual function display, the arguments

and type contradicts with what it has assumed previously. Hence a compile time error

occurs.

7. #include<stdio.h>

void main()

{

char s[]={'a','b','c','\n','c','\0'};

char *p,*str,*str1;

p=&s[3];

str=p;

str1=s;

printf("%d",++*p + ++*str1-32);

}

Answer:

77

A.

Explanation:

p is pointing to character '\n'. str1 is pointing to character 'a' ++*p. "p is pointing to '\n'

and that is incremented by one." the ASCII value of '\n' is 10, which is then incremented to

11. The value of ++*p is 11. ++*str1, str1 is pointing to 'a' that is incremented by 1 and it

becomes 'b'. ASCII value of 'b' is 98.

Now performing (11 + 98 ā€“ 32), we get 77("M");

So we get the output 77 :: "M" (Ascii is 77).

Page 146: EXPRESSIONS - Google Groups

DURGA SOFTAWARE SOLUTIONS

CRT-C Language

DURGA SOFTWARE SOLUTIONS, 23/3RT, 2nd Floor. Opp: Reebok Shoe Room, Near Andhra Bank S.R Nagar, Hyderabad. Cell: 9246212143, Ph: 040-64512786 Page 146

8. If the two strings are identical, then strcmp() function returns

A. -1 B. 1

C. 0 D. Yes

Answer & Explanation

Answer: Option C

Explanation:

Declaration: strcmp(const char *s1, const char*s2);

The strcmp return an int value that is

if s1 < s2 returns a value < 0

if s1 == s2 returns 0

if s1 > s2 returns a value > 0

9.void main()

{

char *p="hai friends",*p1;

p1=p;

while(*p!='\0') ++*p++;

printf("%s %s",p,p1);

}

A. haifriends B. ibj!gsjfoet C. friendshai D.error

Answer:

ibj!gsjfoet

Explanation:

++*p++ will be parse in the given order

ļæ½ *p that is value at the location currently pointed by p will be taken

ļæ½ ++*p the retrieved value will be incremented

ļæ½ when ; is encountered the location will be incremented that is p++ will be executed

Hence, in the while loop initial value pointed by p is ā€žhā€Ÿ, which is changed to ā€žiā€Ÿ by executing

++*p and pointer moves to point, ā€žaā€Ÿ which is similarly changed to ā€žbā€Ÿ and so on. Similarly

blank space is converted to ā€ž!ā€Ÿ. Thus, we obtain value in p becomes ā€œibj!gsjfoetā€ and since p

reaches ā€ž\0ā€Ÿ and p1 points to p thus p1doesnot print anything.

10. Which of the following function is used to find the first occurrence of a given string in

another string?

A. strchr() B. strrchr()

C. strstr() D. strnset()

Page 147: EXPRESSIONS - Google Groups

DURGA SOFTAWARE SOLUTIONS

CRT-C Language

DURGA SOFTWARE SOLUTIONS, 23/3RT, 2nd Floor. Opp: Reebok Shoe Room, Near Andhra Bank S.R Nagar, Hyderabad. Cell: 9246212143, Ph: 040-64512786 Page 147

Answer & Explanation

Answer: Option C

Explanation:

The function strstr() Finds the first occurrence of a substring in another string

Declaration: char *strstr(const char *s1, const char *s2);

Return Value:

On success, strstr returns a pointer to the element in s1 where s2 begins (points to s2 in s1).

On error (if s2 does not occur in s1), strstr returns null.

Example:

#include <stdio.h>

#include <string.h>

int main(void)

{

char *str1 = "Durga Exams", *str2 = "Ex", *ptr;

ptr = strstr(str1, str2);

printf("The substring is: %s\n", ptr);

return 0;

}

Output: The substring is: Exams

11. Will the following code compile

void main()

{

static char names[5][20]={"pascal","ada","cobol","fortran","perl"};

int i;

char *t;

t=names[3];

names[3]=names[4];

names[4]=t;

for (i=0;i<=4;i++)

printf("%s",names[i]);

}

A. Yes B. No

Answer:

Page 148: EXPRESSIONS - Google Groups

DURGA SOFTAWARE SOLUTIONS

CRT-C Language

DURGA SOFTWARE SOLUTIONS, 23/3RT, 2nd Floor. Opp: Reebok Shoe Room, Near Andhra Bank S.R Nagar, Hyderabad. Cell: 9246212143, Ph: 040-64512786 Page 148

Compiler error: Lvalue required in function main

Explanation:

Array names are pointer constants. So it cannot be modified.

12. #include<stdio.h>

void main()

{

char s[]={'a','b','c','\n','c','\0'};

char *p,*str,*str1;

p=&s[3];

str=p;

str1=s;

printf("%c",++*p + ++*str1-32);

}

A. a B. M C.X D.Error

Answer:

M

Explanation:

p is pointing to character '\n'.str1 is pointing to character 'a' ++*p meAnswer:"p

is pointing to '\n' and that is incremented by one." the ASCII value of '\n' is 10.

then it is incremented to 11. the value of ++*p is 11. ++*str1 meAnswer:"str1

is pointing to 'a' that is incremented by 1 and it becomes 'b'. ASCII value of 'b'

is 98. both 11 and 98 is added and result is subtracted from 32.

i.e. (11+98-32)=77("M");

13. Which of the following function is more appropriate for reading in a multi-word string?

A. printf(); B. scanf();

C. gets(); D. puts();

Answer & Explanation

Answer: Option C

Explanation:

gets(); collects a string of characters terminated by a new line from the standard input stream

stdin

#include <stdio.h>

int main(void)

{

char string[60];

printf("Enter a string:");

Page 149: EXPRESSIONS - Google Groups

DURGA SOFTAWARE SOLUTIONS

CRT-C Language

DURGA SOFTWARE SOLUTIONS, 23/3RT, 2nd Floor. Opp: Reebok Shoe Room, Near Andhra Bank S.R Nagar, Hyderabad. Cell: 9246212143, Ph: 040-64512786 Page 149

gets(string);

printf("The string input was: %s\n", string);

return 0;

}

Output:

Enter a string: Durga Exams

The string input was: Durga Exams

51) main( )

{

void *vp;

char ch = ā€žgā€Ÿ, *cp = ā€œgoofyā€;

int j = 20;

vp = &ch;

printf(ā€œ%cā€, *(char *)vp);

vp = &j;

printf(ā€œ%dā€,*(int *)vp);

vp = cp;

printf(ā€œ%sā€,(char *)vp + 3);

}

A. g20fy B. goofy 20fy C. g2fy D.error

Answer:

g20fy

Explanation:

Since a void pointer is used it can be type casted to any other type pointer.

vp = &ch stores address of char ch and the next statement prints the value

stored in vp after type casting it to the proper data type pointer. the output is ā€žgā€Ÿ. Similarly the

output from second printf is ā€ž20ā€Ÿ. The third printf statement type casts it to print the string from

the 4th value hence the output is ā€žfyā€Ÿ.

14 void main ( )

{

static char *s[ ] = {ā€œblackā€, ā€œwhiteā€, ā€œyellowā€, ā€œvioletā€};

char **ptr[ ] = {s+3, s+2, s+1, s}, ***p;

p = ptr;

**++p;

printf(ā€œ%sā€,*--*++p + 3);

}

A. ck B .te C.ow D.et

Answer:

ck

Explanation:

In this problem we have an array of char pointers pointing to start of 4 strings. Then we have ptr

which is a pointer to a pointer of type char and a variable p which is a pointer to a pointer to a

Page 150: EXPRESSIONS - Google Groups

DURGA SOFTAWARE SOLUTIONS

CRT-C Language

DURGA SOFTWARE SOLUTIONS, 23/3RT, 2nd Floor. Opp: Reebok Shoe Room, Near Andhra Bank S.R Nagar, Hyderabad. Cell: 9246212143, Ph: 040-64512786 Page 150

pointer of type char. p hold the initial value of ptr, i.e. p = s+3. The next statement increment

value in p by 1 , thus now value of p = s+2. In the printf statement the expression is evaluated

*++p causes gets value s+1 then the pre decrement is executed and we get s+1 ā€“1 = s . the

indirection operator now gets the value from the array of s and adds 3 to the starting address. The

string is printed starting from this position. Thus, the output is ā€žckā€Ÿ.

15 void main()

{

int i, n;

char *x = ā€œgirlā€;

n = strlen(x);

*x = x[n];

for(i=0; i<n; ++i)

{

printf(ā€œ%s\nā€,x);

x++;

}

}

A.girl

irl

rl

l

(blank space)

B.

(blank space)

irl

rl

l

C. error

D. none of the above

Answer:

B.

(blank space)

irl

rl

l

Explanation:

Here a string (a pointer to char) is initialized with a value ā€œgirlā€. The strlen

function returns the length of the string, thus n has a value 4. The next

statement assigns value at the nth location (ā€ž\0ā€Ÿ) to the first location. Now the string becomes

ā€œ\0irlā€ . Now the printf statement prints the string after each iteration it increments it starting

Page 151: EXPRESSIONS - Google Groups

DURGA SOFTAWARE SOLUTIONS

CRT-C Language

DURGA SOFTWARE SOLUTIONS, 23/3RT, 2nd Floor. Opp: Reebok Shoe Room, Near Andhra Bank S.R Nagar, Hyderabad. Cell: 9246212143, Ph: 040-64512786 Page 151

position. Loop starts from 0 to 4. The first time x[0] = ā€ž\0ā€Ÿ hence it prints nothing and pointer

value is incremented. The second time it prints from x[1] i.e ā€œirlā€ and the third time it prints ā€œrlā€

and the last time it prints ā€œlā€ and the loop terminates.

16. What are the files which are automatically opened when a C file is executed?

Answer:

stdin, stdout, stderr (standard input,standard output,standard error).

17. what will be the position of the file marker?

a: fseek(ptr,0,SEEK_SET);

b: fseek(ptr,0,SEEK_CUR);

Answer :

a: The SEEK_SET sets the file position marker to the starting of the file.

b: The SEEK_CUR sets the file position marker to the current position

of the file.

18. Which of the following function is correct that finds the length of a string?

A.

int xstrlen(char *s)

{

int length=0;

while(*s!='\0')

{ length++; s++; }

return (length);

}

B.

int xstrlen(char s)

{

int length=0;

while(*s!='\0')

length++; s++;

return (length);

}

C.

int xstrlen(char *s)

{

int length=0;

while(*s!='\0')

length++;

return (length);

}

D.

int xstrlen(char *s)

{

int length=0;

while(*s!='\0')

s++;

return (length);

}

Answer & Explanation

Answer: Option A

Explanation:

Option A is the correct function to find the length of given string.

Example:

#include<stdio.h>

Page 152: EXPRESSIONS - Google Groups

DURGA SOFTAWARE SOLUTIONS

CRT-C Language

DURGA SOFTWARE SOLUTIONS, 23/3RT, 2nd Floor. Opp: Reebok Shoe Room, Near Andhra Bank S.R Nagar, Hyderabad. Cell: 9246212143, Ph: 040-64512786 Page 152

int xstrlen(char *s)

{

int length=0;

while(*s!='\0')

{ length++; s++; }

return (length);

}

int main()

{

char d[] = "Durga Exams";

printf("Length = %d\n", xstrlen(d));

return 0;

}

Output: Length = 11

20. What will be the output of the program ?

#include<stdio.h>

#include<string.h>

int main()

{

char str1[20] = "Hello", str2[20] = " World";

printf("%s\n", strcpy(str2, strcat(str1, str2)));

return 0;

}

A. Hello B. World

C. Hello World D. WorldHello

Answer & Explanation

Answer: Option C

Explanation:

Step 1: char str1[20] = "Hello", str2[20] = " World"; The variable str1 and str2 is declared as an

array of characters and initialized with value "Hello" and " World" respectively.

Step 2: printf("%s\n", strcpy(str2, strcat(str1, str2)));

=> strcat(str1, str2)) it append the string str2 to str1. The result will be stored in str1. Therefore

str1 contains "Hello World".

=> strcpy(str2, "Hello World") it copies the "Hello World" to the variable str2.

Page 153: EXPRESSIONS - Google Groups

DURGA SOFTAWARE SOLUTIONS

CRT-C Language

DURGA SOFTWARE SOLUTIONS, 23/3RT, 2nd Floor. Opp: Reebok Shoe Room, Near Andhra Bank S.R Nagar, Hyderabad. Cell: 9246212143, Ph: 040-64512786 Page 153

Hence it prints "Hello World".

25. void main()

{

char *str1="abcd";

char str2[]="abcd";

printf("%d %d %d",sizeof(str1),sizeof(str2),sizeof("abcd"));

}

A. 4 4 4 B. 2 5 5 C. 2 2 2 d.error

Answer:

B.2 5 5

Explanation:

In first sizeof, str1 is a character pointer so it gives you the size of the pointer

variable. In second sizeof the name str2 indicates the name of the array

whose size is 5 (including the '\0' termination character). The third sizeof is

similar to the second one.

26. What will be the output of the program ?

#include<stdio.h>

int main()

{

char p[] = "%d\n";

p[1] = 'c';

printf(p, 65);

return 0;

}

A. A B. a

C. c D. 65

Answer & Explanation

Answer: Option A

Explanation:

Step 1: char p[] = "%d\n"; The variable p is declared as an array of characters and initialized

with string "%d".

Step 2: p[1] = 'c'; Here, we overwrite the second element of array p by 'c'. So array p becomes

"%c".

Step 3: printf(p, 65); becomes printf("%c", 65);

Page 154: EXPRESSIONS - Google Groups

DURGA SOFTAWARE SOLUTIONS

CRT-C Language

DURGA SOFTWARE SOLUTIONS, 23/3RT, 2nd Floor. Opp: Reebok Shoe Room, Near Andhra Bank S.R Nagar, Hyderabad. Cell: 9246212143, Ph: 040-64512786 Page 154

Therefore it prints the ASCII value of 65. The output is 'A'.

27. What will be the output of the program ?

#include<stdio.h>

#include<string.h>

int main()

{

printf("%d\n", strlen("12345"));

return 0;

}

A. 5 B. 12

C. 6 D. 2

Answer & Explanation

Answer: Option A

Explanation:

The function strlen returns the number of characters in the given string.

Therefore, strlen("12345") returns 5.

Hence the output of the program is "5".

28. What will be the output of the program ?

#include<stdio.h>

int main()

{

printf(5+"Good Morning\n");

return 0;

}

A. Good Morning B. Good

C. M D. Morning

Answer & Explanation

Answer: Option D

Explanation:

printf(5+"Good Morning\n"); It skips the 5 characters and prints the given string.

Hence the output is "Morning"

Page 155: EXPRESSIONS - Google Groups

DURGA SOFTAWARE SOLUTIONS

CRT-C Language

DURGA SOFTWARE SOLUTIONS, 23/3RT, 2nd Floor. Opp: Reebok Shoe Room, Near Andhra Bank S.R Nagar, Hyderabad. Cell: 9246212143, Ph: 040-64512786 Page 155

This can also be written as printf("Good Morning\n"+5); or

printf(ā€œ%sā€,5+"Good Morning\n");

29. What will be the output of the program ?

#include<stdio.h>

#include<string.h>

int main()

{

char str[] = "Durga\0\ROCKS\0";

printf("%s\n", str);

return 0;

}

A. ROCKS B. Durga

C. Durga ROCKS D. Durga\0ROCKS

Answer & Explanation

Answer: Option B

Explanation:

A string is a collection of characters terminated by '\0'.

Step 1: char str[] = "Durga\0\ROCKS\0"; The variable str is declared as an array of characters

and initialized with value "Durga"

Step 2: printf("%s\n", str); It prints the value of the str.

The output of the program is "Durga".

30. What will be the output of the program If characters 'a', 'b' ,'c',ā€Ÿdā€Ÿ ans enter are supplied as

input?

#include<stdio.h>

int main()

{

void fun();

fun();

printf("\n");

return 0;

}

void fun()

{

char c;

Page 156: EXPRESSIONS - Google Groups

DURGA SOFTAWARE SOLUTIONS

CRT-C Language

DURGA SOFTWARE SOLUTIONS, 23/3RT, 2nd Floor. Opp: Reebok Shoe Room, Near Andhra Bank S.R Nagar, Hyderabad. Cell: 9246212143, Ph: 040-64512786 Page 156

if((c = getchar())!= '\n')

fun();

printf("%c", c);

}

A. abcd abcd B. dbca

C. Infinite loop D. dcba

Answer & Explanation

Answer: Option D

Explanation:

Step 1: void fun(); This is the prototype for the function fun().

Step 2: fun(); The function fun() is called here.

The function fun() gets a character input and the input is terminated by an enter key(New line

character). Due to recursion ,it prints the given character in the reverse order.

The given input characters are "abcd"and \n

Output: dcba

31.What will be the output of the program ?

#include<stdio.h>

int main()

{

printf("Durga", "ROCKS\n");

return 0;

}

A. Error B. Durga ROCKS

C. Durga D. ROCKS

Answer & Explanation

Answer: Option C

Explanation:

printf("Durga", "ROCKS\n"); It prints "Durga". Because ,(comma) operator has Left to Right

associativity. After printing "Durga", the statement got terminated.

Page 157: EXPRESSIONS - Google Groups

DURGA SOFTAWARE SOLUTIONS

CRT-C Language

DURGA SOFTWARE SOLUTIONS, 23/3RT, 2nd Floor. Opp: Reebok Shoe Room, Near Andhra Bank S.R Nagar, Hyderabad. Cell: 9246212143, Ph: 040-64512786 Page 157

32. What will be the output of the program ?

#include<stdio.h>

int main()

{

char *names[] = { "Suresh", "Siva", "Sona", "Baiju", "Ritu"};

int i;

char *t;

t = names[3];

names[3] = names[4];

names[4] = t;

for(i=0; i<=4; i++)

printf("%s,", names[i]);

return 0;

}

A. Suresh, Siva, Sona, Baiju, Ritu

B. Suresh, Siva, Sona, Ritu, Baiju

C. Suresh, Siva, Baiju, Sona, Ritu

D. Suresh, Siva, Ritu, Sona, Baiju

Answer & Explanation

Answer: Option B

Explanation:

Step 1: char *names[] = { "Suresh", "Siva", "Sona", "Baiju", "Ritu"}; The variable names is

declared as an pointer to a array of strings.

Step 2: int i; The variable i is declared as an integer type.

Step 3: char *t; The variable t is declared as pointer to a string.

Step 4: t = names[3]; names[3] = names[4]; names[4] = t; These statements the swaps the 4 and

5 element of the array names.

Step 5: for(i=0; i<=4; i++) printf("%s,", names[i]); These statement prints the all the value of the

array names.

Hence the output of the program is "Suresh, Siva, Sona, Ritu, Baiju".

33. What will be the output of the program ?

#include<stdio.h>

#include<string.h>

int main()

{

static char str1[] = "dills";

static char str2[20];

static char str3[] = "Daffo";

Page 158: EXPRESSIONS - Google Groups

DURGA SOFTAWARE SOLUTIONS

CRT-C Language

DURGA SOFTWARE SOLUTIONS, 23/3RT, 2nd Floor. Opp: Reebok Shoe Room, Near Andhra Bank S.R Nagar, Hyderabad. Cell: 9246212143, Ph: 040-64512786 Page 158

int i;

i = strcmp(strcat(str3, strcpy(str2, str1)), "Daffodills");

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

return 0;

}

[A]. 0

[B]. 1

[C]. 2 [D]. 4

Answer: Option A

Explanation:

step 1: strcpy(str2,str1) cpoy the str1="dills" into str2.

step 2: strcat(str3,str2) append the dills at the end of Daffo.

step 3: strcmp(str3,"Daffodils") returns the no. of charecters of str3 which are not find in

Daffodills.

step 4: since both strings are same so results will be 0(zero)

34.. What will be the output of the program ?

#include<stdio.h>

#include<string.h>

int main()

{

static char s[] = "Hello!";

printf("%d\n", *(s+strlen(s)));

return 0;

}

A. 8 B. 0

C. 16 D. Error

Answer & Explanation

Answer: Option B

Explanation:

Length of the string will be 6. 's' is a pointer which is pointing to the first character of the string.

After getting incremented its value by 6 it will point to null character, having ASCII value 0. So

0 will be printed.

Page 159: EXPRESSIONS - Google Groups

DURGA SOFTAWARE SOLUTIONS

CRT-C Language

DURGA SOFTWARE SOLUTIONS, 23/3RT, 2nd Floor. Opp: Reebok Shoe Room, Near Andhra Bank S.R Nagar, Hyderabad. Cell: 9246212143, Ph: 040-64512786 Page 159

35. What will be the output of the program ?

#include<stdio.h>

int main()

{

static char s[25] = "The cocaine man";

int i=0;

char ch;

ch = s[++i];

printf("%c", ch);

ch = s[i++];

printf("%c", ch);

ch = i++[s];

printf("%c", ch);

ch = ++i[s];

printf("%c", ch);

return 0;

}

A. hhe! B. he c

C. The c D. Hhec

Answer & Explanation

Answer: Option A

36. What will be the output of the program ?

#include<stdio.h>

int main()

{

int i;

char a[] = "\0";

if(printf("%s", a))

printf("The string is empty\n");

else

printf("The string is not empty\n");

return 0;

}

A. The string is empty B. The string is not empty

C. No output D. 0

Answer & Explanation

Answer: Option B

Page 160: EXPRESSIONS - Google Groups

DURGA SOFTAWARE SOLUTIONS

CRT-C Language

DURGA SOFTWARE SOLUTIONS, 23/3RT, 2nd Floor. Opp: Reebok Shoe Room, Near Andhra Bank S.R Nagar, Hyderabad. Cell: 9246212143, Ph: 040-64512786 Page 160

Explanation:

The function printf() returns the number of charecters printed on the console.

Step 1: char a[] = "\0"; The variable a is declared as an array of characters and it initialized with

"\0". It denotes that the string is empty.

Step 2: if(printf("%s", a)) The printf() statement does not print anything, so it returns '0'(zero).

Hence the if condition is failed.

In the else part it prints "The string is not empty".

37.If char=1, int=4, and float=4 bytes size, What will be the output of the program ?

#include<stdio.h>

int main()

{

char ch = 'A';

printf("%d, %d, %d", sizeof(ch), sizeof('A'), sizeof(3.14f));

return 0;

}

A. 1, 2, 4 B. 1, 4, 4

C. 2, 2, 4 D. 2, 4, 8

Answer & Explanation

Answer: Option B

Explanation: Step 1: char ch = 'A'; The variable ch is declared as an character type and initialized with value

'A'.

Step 2: printf("%d, %d, %d", sizeof(ch), sizeof('A'), sizeof(3.14));

The sizeof function returns the size of the given expression.

sizeof(ch) becomes sizeof(char). The size of char is 1 byte.

sizeof('A') becomes sizeof(65). The size of int is 4 bytes (as mentioned in the question).

sizeof(3.14f). The size of float is 4 bytes.

Hence the output of the program is 1, 4, 4

38. If the size of pointer is 32 bits What will be the output of the program ?

#include<stdio.h>

int main()

{

char a[] = "Visual C++";

char *b = "Visual C++";

printf("%d, %d\n", sizeof(a), sizeof(b));

printf("%d, %d", sizeof(*a), sizeof(*b));

Page 161: EXPRESSIONS - Google Groups

DURGA SOFTAWARE SOLUTIONS

CRT-C Language

DURGA SOFTWARE SOLUTIONS, 23/3RT, 2nd Floor. Opp: Reebok Shoe Room, Near Andhra Bank S.R Nagar, Hyderabad. Cell: 9246212143, Ph: 040-64512786 Page 161

return 0;

}

A.

10, 2

2, 2 B.

10, 4

1, 2

C.

11, 4

1, 1 D.

12, 2

2, 2

Answer & Explanation

Answer: Option C

Explanation:

Char a[] has 10 letters and 1 escape character \0(null) so size of will give 11, size of pointer is 32

bit = 4 byte (1 byte = 8 bits), *a points to char V so sizeof(V) = 1 similarly *b also points to V.

39. What will be the output of the program ?

#include<stdio.h>

int main()

{

char str1[] = "Hello";

char str2[10];

char *t, *s;

s = str1;

t = str2;

while(*t=*s)

*t++ = *s++;

printf("%s\n", str2);

return 0;

}

[A]. Hello

[B]. HelloHello

[C]. No output [D]. ello

Answer: Option A

Explanation:

Here s will points to the beginig of string str1.

And t will points to the begining address of string str2.

In while loop we are copying the elements from str1 to str2 using pointers s and t untill end of

string is reached. At last when s[n] == '\0' then ( *t=*s ) == zero, so it is false, so the loop will

exit.The above can be written in one step while(*t++=*s); most of the time asked in interviews

.this is copying of string in single line.

Page 162: EXPRESSIONS - Google Groups

DURGA SOFTAWARE SOLUTIONS

CRT-C Language

DURGA SOFTWARE SOLUTIONS, 23/3RT, 2nd Floor. Opp: Reebok Shoe Room, Near Andhra Bank S.R Nagar, Hyderabad. Cell: 9246212143, Ph: 040-64512786 Page 162

40. What will be the output of the program ?

#include<stdio.h>

int main()

{

char str[50] = "Durga Exams";

printf("%s\n", &str+2);

return 0;

}

A. Garbage value B. Error

C. No output D. rga Exams

Answer & Explanation

Answer: Option A

Explanation:

Step 1: char str[50] = "Durga Exams"; The variable str is declared as an array of characteres and

initialized with a string "Durga Exams".

Step 2: printf("%s\n", &str+2);

=> In the printf statement %s is string format specifier tells the compiler to print the string in the

memory of &str+2

=> &str is a location of string "Durga Exams". Therefore &str+2 is another memory location.

Hence it prints the Garbage value.

41. What will be the output of the program ?

#include<stdio.h>

int main()

{

char str = "Durga Exams";

printf("%s\n", str);

return 0;

}

A. Error B. Durga Exams

C. Base address of str D. No output

Answer & Explanation

Page 163: EXPRESSIONS - Google Groups

DURGA SOFTAWARE SOLUTIONS

CRT-C Language

DURGA SOFTWARE SOLUTIONS, 23/3RT, 2nd Floor. Opp: Reebok Shoe Room, Near Andhra Bank S.R Nagar, Hyderabad. Cell: 9246212143, Ph: 040-64512786 Page 163

Answer: Option A

Explanation:

The line char str = "Durga Exams"; generates "Non portable pointer conversion" error.

To eliminate the error, we have to change the above line to

char *str = "Durga Exams"; (or) char str[] = "Durga Exams";

Then it prints "Durga Exams".

42. What will be the output of the program ?

#include<stdio.h>

int main()

{

char str[] = "Nagpur";

str[0]='K';

printf("%s, ", str);

str = "Kanpur";

printf("%s", str+1);

return 0;

}

A. Kagpur, Kanpur B. Nagpur, Kanpur

C. Kagpur, anpur D. Error

Answer & Explanation

Answer: Option D

Explanation:

The statement str = "Kanpur"; generates the LVALUE required error. We have to use strcpy

function to copy a string.To remove error we have to change this statement str = "Kanpur"; to

strcpy(str, "Kanpur");The program prints the string "anpur"

43. What will be the output of the program ?

#include<stdio.h>

#include<string.h>

int main()

{

char sentence[80];

int i;

printf("Enter a line of text\n");

Page 164: EXPRESSIONS - Google Groups

DURGA SOFTAWARE SOLUTIONS

CRT-C Language

DURGA SOFTWARE SOLUTIONS, 23/3RT, 2nd Floor. Opp: Reebok Shoe Room, Near Andhra Bank S.R Nagar, Hyderabad. Cell: 9246212143, Ph: 040-64512786 Page 164

gets(sentence);

for(i=strlen(sentence)-1; i >=0; i--)

putchar(sentence[i]);

return 0;

}

[A]. The sentence will get printed in same order as it entered

[B]. The sentence will get printed in reverse order

[C]. Half of the sentence will get printed

[D]. None of above

Answer: Option B

Explanation:

In for loop we initializing i with 1 less the length of the string, so i points to the last element of

the string(before null character), and we printing each character and decrementing i by 1 which

willl print the characters in reverse order.

44. What will be the output of the program ?

#include<stdio.h>

void swap(char *, char *);

int main()

{

char *pstr[2] = {"Hello", "Durga Exams"};

swap(pstr[0], pstr[1]);

printf("%s\n%s", pstr[0], pstr[1]);

return 0;

}

void swap(char *t1, char *t2)

{

char *t;

t=t1;

t1=t2;

t2=t;

}

A.

Durga Exams

Hello B. Address of "Hello" and "Durga Exams"

C.

Hello

Durga Exams D.

Dello

Hurga Exams

Answer & Explanation

Answer: Option C

Page 165: EXPRESSIONS - Google Groups

DURGA SOFTAWARE SOLUTIONS

CRT-C Language

DURGA SOFTWARE SOLUTIONS, 23/3RT, 2nd Floor. Opp: Reebok Shoe Room, Near Andhra Bank S.R Nagar, Hyderabad. Cell: 9246212143, Ph: 040-64512786 Page 165

Explanation:

Step 1: void swap(char *, char *); This prototype tells the compiler that the function swap accept

two strings as arguments and it does not return anything.

Step 2: char *pstr[2] = {"Hello", "Durga Exams"}; The variable pstr is declared as an pointer to

the array of strings. It is initialized to

pstr[0] = "Hello", pstr[1] = "Durga Exams"

Step 3: swap(pstr[0], pstr[1]); The swap function is called by "call by value". Hence it does not

affect the output of the program.

If the swap function is "called by reference" it will affect the variable pstr.

Step 4: printf("%s\n%s", pstr[0], pstr[1]); It prints the value of pstr[0] and pstr[1].

Hence the output of the program is

Hello

Durga Exams

45. If the size of pointer is 4 bytes then What will be the output of the program ?

#include<stdio.h>

int main()

{

char *str[] = {"Frogs", "Do", "Not", "Die", "They", "Croak!"};

printf("%d, %d", sizeof(str), strlen(str[0]));

return 0;

}

A. 22, 4 B. 25, 5

C. 24, 5 D. 20, 2

Answer & Explanation

Answer: Option C

Explanation:

Step 1: char *str[] = {"Frogs", "Do", "Not", "Die", "They", "Croak!"}; The variable str is

declared as an pointer to the array of 6 strings.

Step 2: printf("%d, %d", sizeof(str), strlen(str[0]));

sizeof(str) denotes 6 * 4 bytes = 24 bytes. Hence it prints '24'

strlen(str[0])); becomes strlen(Frogs)). Hence it prints '5';

Hence the output of the program is 24, 5

46. What will be the output of the program ?

#include<stdio.h>

#include<string.h>

int main()

{

char str1[5], str2[5];

int i;

Page 166: EXPRESSIONS - Google Groups

DURGA SOFTAWARE SOLUTIONS

CRT-C Language

DURGA SOFTWARE SOLUTIONS, 23/3RT, 2nd Floor. Opp: Reebok Shoe Room, Near Andhra Bank S.R Nagar, Hyderabad. Cell: 9246212143, Ph: 040-64512786 Page 166

gets(str1);

gets(str2);

i = strcmp(str1, str2);

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

return 0;

}

A. Unpredictable integer value B. 0

C. -1 D. Error

Answer & Explanation

Answer: Option A

Explanation:

gets() gets collects a string of characters terminated by a new line from the standard input stream

stdin.

The gets(str1) read the input string from user and store in variable str1.

The gets(str2) read the input string from user and store in variable str2.

The code i = strcmp(str1, str2); The strcmp not only returns -1, 0 and +1, but also other negative

or positive values. So the value of i is "unpredictable integer value".

printf("%d\n", i); It prints the value of variable i.

47. What will be the output of the program ?

#include<stdio.h>

int main()

{

char str1[] = "Hello";

char str2[] = "Hello";

if(str1 == str2)

printf("Equal\n");

else

printf("Unequal\n");

return 0;

}

A. Equal B. Unequal

C. Error D. None of above

Answer & Explanation

Answer: Option B

Explanation:

Page 167: EXPRESSIONS - Google Groups

DURGA SOFTAWARE SOLUTIONS

CRT-C Language

DURGA SOFTWARE SOLUTIONS, 23/3RT, 2nd Floor. Opp: Reebok Shoe Room, Near Andhra Bank S.R Nagar, Hyderabad. Cell: 9246212143, Ph: 040-64512786 Page 167

Step 1: char str1[] = "Hello"; The variable str1 is declared as an array of characters and

initialized with a string "Hello".

Step 2: char str2[] = "Hello"; The variable str2 is declared as an array of characters and

initialized with a string "Hello".

We have to use strcmp(s1,s2) function to compare strings.

Step 3: if(str1 == str2) here the address of str1 and str2 are compared. The address of both

variable is not same. Hence the if condition is failed.

Step 4: At the else part it prints "Unequal"

48.What will be the output of the program ?

#include<stdio.h>

int main()

{

char *p1 = "Durga", *p2;

p2=p1;

p1 = "EXAMS";

printf("%s %s\n", p1, p2);

return 0;

}

A. Durga EXAMS B. EXAMS Durga

C. Durga Durga D. EXAMS EXAMS

Answer & Explanation

Answer: Option B

Explanation:

Step 1: char *p1 = "Durga", *p2; The variable p1 and p2 is declared as an pointer to a character

value and p1 is assigned with a value "Durga".

Step 2: p2=p1; The value of p1 is assigned to variable p2. So p2 contains "Durga".

Step 3: p1 = "EXAMS"; The p1 is assigned with a string "EXAMS"

Step 4: printf("%s %s\n", p1, p2); It prints the value of p1 and p2.

Hence the output of the program is "EXAMS Durga".

49. What will be the output of the program ?

#include<stdio.h>

#include<string.h>

int main()

{

printf("%c\n", "abcdefgh"[4]);

return 0;

}

A. Error B. d

Page 168: EXPRESSIONS - Google Groups

DURGA SOFTAWARE SOLUTIONS

CRT-C Language

DURGA SOFTWARE SOLUTIONS, 23/3RT, 2nd Floor. Opp: Reebok Shoe Room, Near Andhra Bank S.R Nagar, Hyderabad. Cell: 9246212143, Ph: 040-64512786 Page 168

C. e D. abcdefgh

Answer & Explanation

Answer: Option C

Explanation:

printf("%c\n", "abcdefgh"[4]); It prints the 5 character of the string "abcdefgh".

Hence the output is 'e'.

50. What will be the output of the program ?

#include<stdio.h>

int main()

{

printf("%u %s\n", &"Hello", &"Hello");

return 0;

}

A. 65530 Hello B. Hello 65530

C. Hello Hello D. Error

Answer & Explanation

Answer: Option A

Explanation:

In printf("%u %s\n", &"Hello", &"Hello");.

The %u format specifier tells the compiler to print the memory address of the "Hello".

The %s format specifier tells the compiler to print the string "Hello".

Hence the output of the program is "65530 Hello". (Note: 65530 is memory address it may

change.)

51. Which of the following statements are correct about the program below?

#include<stdio.h>

int main()

{

char str[20], *s;

printf("Enter a string\n");

scanf("%s", str);

s=str;

while(*s != '\0')

{

Page 169: EXPRESSIONS - Google Groups

DURGA SOFTAWARE SOLUTIONS

CRT-C Language

DURGA SOFTWARE SOLUTIONS, 23/3RT, 2nd Floor. Opp: Reebok Shoe Room, Near Andhra Bank S.R Nagar, Hyderabad. Cell: 9246212143, Ph: 040-64512786 Page 169

if(*s >= 97 && *s <= 122)

*s = *s-32;

s++;

}

printf("%s",str);

return 0;

}

A. The code converts a string in to an integer

B. The code converts lower case character to upper case

C. The code converts upper case character to lower case

D. Error in code

Answer & Explanation

Answer: Option B

Explanation:

This program converts the given string to upper case string.

Output:

Enter a string: durga exams

DURGA EXAMS

52. Which of the following statements are correct about the below declarations?

char *p = "Durga";

char a[] = "Durga";

1: There is no difference in the declarations and both serve the same purpose.

2: p is a non-const pointer pointing to a non-const string, whereas a is a const pointer pointing to

a non-const pointer.

3: The pointer p can be modified to point to another string, whereas the individual characters

within array a can be changed.

4: In both cases the '\0' will be added at the end of the string "Durga".

A. 1, 2 B. 2, 3, 4

C. 3, 4 D. 2, 3

Answer & Explanation

Answer: Option B

53. Which of the following statements are correct ?

1: A string is a collection of characters terminated by '\0'.

2: The format specifier %s is used to print a string.

3: The length of the string can be obtained by strlen().

4: The pointer CAN work on string.

Page 170: EXPRESSIONS - Google Groups

DURGA SOFTAWARE SOLUTIONS

CRT-C Language

DURGA SOFTWARE SOLUTIONS, 23/3RT, 2nd Floor. Opp: Reebok Shoe Room, Near Andhra Bank S.R Nagar, Hyderabad. Cell: 9246212143, Ph: 040-64512786 Page 170

A. A, B B. A, B, C,D

C. B, D D. C, D

Answer & Explanation

Answer: Option B

Explanation:

Clearly, four statements is correct.

54. Which of the following statement is correct?

A. strcmp(s1, s2) returns a number less than 0 if s1>s2

B. strcmp(s1, s2) returns a number greater than 0 if s1<s2

C. strcmp(s1, s2) returns 0 if s1==s2

D. strcmp(s1, s2) returns 1 if s1==s2

Answer & Explanation

Answer: Option C

Explanation:

The strcmp return an int value that is

if s1 < s2 returns a value < 0

if s1 == s2 returns 0

if s1 > s2 returns a value > 0

From the above statements, that the third statement is only correct.

55.will the program compile successfully?

#include<stdio.h>

int main()

{

char a[] = "Durga";

char *p = "EXAMS";

a = "EXAMS";

p = "Durga";

printf("%s %s\n", a, p);

return 0;

}

Page 171: EXPRESSIONS - Google Groups

DURGA SOFTAWARE SOLUTIONS

CRT-C Language

DURGA SOFTWARE SOLUTIONS, 23/3RT, 2nd Floor. Opp: Reebok Shoe Room, Near Andhra Bank S.R Nagar, Hyderabad. Cell: 9246212143, Ph: 040-64512786 Page 171

A. Yes B. No

Answer & Explanation

Answer: Option B

Explanation: Because we can assign a new string to a pointer but not to an array a.

56. For the following statements will arr[3] and ptr[3] fetch the same character?

char arr[] = "Durga Exams";

char *ptr = "Durga Exams";

A. Yes B. No

Answer & Explanation

Answer: Option A

Explanation:

Yes, both the statements print the same character 'g'.

Page 172: EXPRESSIONS - Google Groups

DURGA SOFTAWARE SOLUTIONS

CRT-C Language

DURGA SOFTWARE SOLUTIONS, 23/3RT, 2nd Floor. Opp: Reebok Shoe Room, Near Andhra Bank S.R Nagar, Hyderabad. Cell: 9246212143, Ph: 040-64512786 Page 172

Structures ,Unions ,Enums

1.What is the similarity between a structure, union and enumeration?

A. All of them let you define new values

B. All of them let you define new data types

C. All of them let you define new pointers

D. All of them let you define new structures

Answer & Explanation

Answer: Option B

Explanation:

structures unions and enumeration is used to create a new datatype .

2. #include<stdio.h>

void main()

{

struct xx

{

int x=3;

char name[]="hello";

};

struct xx *s;

printf("%d",s->x);

printf("%s",s->name);

}

A. 3 hello B.Compiler Error C. hello 3 D. none of the above

Answer:

Compiler Error

Explanation:

You should not initialize variables in declaration

3. The following code will compile

#include<stdio.h>

void main()

{

struct xx

{

int x;

Page 173: EXPRESSIONS - Google Groups

DURGA SOFTAWARE SOLUTIONS

CRT-C Language

DURGA SOFTWARE SOLUTIONS, 23/3RT, 2nd Floor. Opp: Reebok Shoe Room, Near Andhra Bank S.R Nagar, Hyderabad. Cell: 9246212143, Ph: 040-64512786 Page 173

struct yy

{

char s;

struct xx *p;

};

struct yy *q;

};

}

A. Ture B.False

Answer:

B.False

Compiler Error

Explanation:

The structure yy is nested within structure xx. Hence, the elements are of yy

are to be accessed through the instance of structure xx, which needs an instance of yy to be

known. If the instance is created after defining the structure the compiler will not know about

the instance relative to xx. Hence for nested structure yy you have to declare member.

4. What will be the output of the program ?

#include<stdio.h>

int main()

{

union a

{

int i;

char ch[2];

};

union a u;

u.ch[0]=3;

u.ch[1]=2;

printf("%d, %d, %d\n", u.ch[0], u.ch[1], u.i);

return 0;

}

A. 3, 2, 515 B. 515, 2, 3

C. 3, 2, 5 D. 515, 515, 4

Answer & Explanation

Answer: Option A

Explanation:

The system will allocate 2 bytes for the union.

Page 174: EXPRESSIONS - Google Groups

DURGA SOFTAWARE SOLUTIONS

CRT-C Language

DURGA SOFTWARE SOLUTIONS, 23/3RT, 2nd Floor. Opp: Reebok Shoe Room, Near Andhra Bank S.R Nagar, Hyderabad. Cell: 9246212143, Ph: 040-64512786 Page 174

The statements u.ch[0]=3; u.ch[1]=2; store data in memory as given below

5. What will be the output of the program ?

#include<stdio.h>

int main()

{

union var

{

int a, b;

};

union var v;

v.a=10;

v.b=20;

printf("%d\n", v.a);

return 0;

}

A. 10 B. 20

C. 30 D. 0

Answer & Explanation

Answer: Option B

Explanation:

In union the memory will be allocated for the highest data type.

Here the size of union is two bytes not four bytes. Hence 10 will be overwritten by 20. So the

output is 20

Page 175: EXPRESSIONS - Google Groups

DURGA SOFTAWARE SOLUTIONS

CRT-C Language

DURGA SOFTWARE SOLUTIONS, 23/3RT, 2nd Floor. Opp: Reebok Shoe Room, Near Andhra Bank S.R Nagar, Hyderabad. Cell: 9246212143, Ph: 040-64512786 Page 175

6. What will be the output of the program ?

#include<stdio.h>

int main()

{

struct value

{

int bit1:1;

int bit3:4;

int bit4:4;

}bit={1, 2, 13};

printf("%d, %d, %d\n", bit.bit1, bit.bit3, bit.bit4);

return 0;

}

A. 1, 2, 13 B. 1, 4, 4

C. -1, 2, -3 D. -1, -2, -13

Answer & Explanation

Answer: Option C

Explanation:

Note the below statement inside the struct:

int bit1:1; --> 'int' indicates that it is a SIGNED integer.

For signed integers the leftmost bit will be taken for +/- sign.

If you store 1 in 1-bit field: The left most bit is 1, so the system will treat the value as negative number.

The 2's complement method is used by the system to handle the negative values.

Therefore, the data stored is 1. The 2's complement of 1 is also 1 (negative).

Therefore -1 is printed.

If you store 2 in 4-bits field: Binary 2: 0010 (left most bit is 0, so system will treat it as positive value)

0010 is 2

Therefore 2 is printed.

If you store 13 in 4-bits field: Binary 13: 1101 (left most bit is 1, so system will treat it as negative value)

Find 2's complement of 1101:

1's complement of 1101 : 0010

2's complement of 1101 : 0011 (Add 1 to the result of 1's complement)

0011 is 3 (but negative value)

Therefore -3 is printed.

7. void main()

{

Page 176: EXPRESSIONS - Google Groups

DURGA SOFTAWARE SOLUTIONS

CRT-C Language

DURGA SOFTWARE SOLUTIONS, 23/3RT, 2nd Floor. Opp: Reebok Shoe Room, Near Andhra Bank S.R Nagar, Hyderabad. Cell: 9246212143, Ph: 040-64512786 Page 176

char far *farther,*farthest;

printf("%d..%d",sizeof(farther),sizeof(farthest));

}

A. 4..2 B. 2..2 C.8.. 8 D.2..4

Answer:

4..2

Explanation:

the second pointer is of char type and not a far pointer

8. What will be the output of the program ?

#include<stdio.h>

int main()

{

struct value

{

int bit1:2;

int bit3:5;

int bit4:4;

}bit;

printf("%d\n", sizeof(bit));

return 0;

}

A. 1 B. 2

C. 4 D. 11

Answer & Explanation

Answer: Option B

Explanation:

Since C is a compiler dependent language, in Turbo C (Windows) the output will be 2, but in

GCC (Linux) the output will be 4.

9. Will the following code compile

#include<stdio.h>

void main()

{

struct xx

{

int x=3;

char name[]="hello";

};

struct xx *s=malloc(sizeof(struct xx));

Page 177: EXPRESSIONS - Google Groups

DURGA SOFTAWARE SOLUTIONS

CRT-C Language

DURGA SOFTWARE SOLUTIONS, 23/3RT, 2nd Floor. Opp: Reebok Shoe Room, Near Andhra Bank S.R Nagar, Hyderabad. Cell: 9246212143, Ph: 040-64512786 Page 177

printf("%d",s->x);

printf("%s",s->name);

}

A. Yes B. No

Answer:

Compiler Error

Explanation:

Initialization should not be done for structure members inside the structure

Declaration

10. What will be the output of the program ?

#include<stdio.h>

int main()

{

enum days {MON=-1, TUE, WED=6, THU, FRI, SAT};

printf("%d, %d, %d, %d, %d, %d\n", MON, TUE, WED, THU, FRI, SAT);

return 0;

}

A. -1, 0, 1, 2, 3, 4 B. -1, 2, 6, 3, 4, 5

C. -1, 0, 6, 2, 3, 4 D. -1, 0, 6, 7, 8, 9

Answer: Option D

Explanation:

In Enum by default cur=prev+1, here mon=-1 so tue will be assigned to 0(tue=mon+1) even

you can overwrite with your own value for eg wed=6 so thu will become 7.

11.The following code is for single linked lists

struct aaa{

struct aaa *prev;

int i;

struct aaa *next;

};

main()

{

struct aaa abc,def,ghi,jkl;

int x=100;

abc.i=0;

abc.prev=&jkl;

abc.next=&def;

def.i=1;

Page 178: EXPRESSIONS - Google Groups

DURGA SOFTAWARE SOLUTIONS

CRT-C Language

DURGA SOFTWARE SOLUTIONS, 23/3RT, 2nd Floor. Opp: Reebok Shoe Room, Near Andhra Bank S.R Nagar, Hyderabad. Cell: 9246212143, Ph: 040-64512786 Page 178

def.prev=&abc;

def.next=&ghi;

ghi.i=2;

ghi.prev=&def;

ghi.next=&jkl;

jkl.i=3;

jkl.prev=&ghi;

jkl.next=&abc;

x=abc.next->next->prev->next->i;

printf("%d",x);

}

A. Yes B. No

Answer:

B. No

Output: 2

Explanation:

above all statements form a double circular linked list;

abc.next->next->prev->next->i

this one points to "ghi" node the value of at particular node is 2.

12.Will the following code compile

struct point

{

int x;

int y;

};

struct point origin,*pp;

main()

{

pp=&origin;

printf("origin is(%d%d)\n",(*pp).x,(*pp).y);

printf("origin is (%d%d)\n",pp->x,pp->y);

}

A. Yes B. No

Answer:

Yes

Output:

origin is(0,0)

origin is(0,0)

Explanation:

pp is a pointer to structure. we can access the elements of the structure either

with arrow mark or with indirection operator.

Page 179: EXPRESSIONS - Google Groups

DURGA SOFTAWARE SOLUTIONS

CRT-C Language

DURGA SOFTWARE SOLUTIONS, 23/3RT, 2nd Floor. Opp: Reebok Shoe Room, Near Andhra Bank S.R Nagar, Hyderabad. Cell: 9246212143, Ph: 040-64512786 Page 179

Note:

Since structure point is globally declared x & y are initialized as zeroes

13. What will be the output of the program ?

#include<stdio.h>

int main()

{

struct employee

{

char *n;

int age;

};

struct employee e1 = {"Dravid", 23};

struct employee e2 = e1;

strupr(e2.n);

printf("%s\n", e1.n);

return 0;

}

A. Error: Invalid structure assignment

B. DRAVID

C. Dravid

D. No output

Answer & Explanation

Answer: Option C

Explanation:

The value of e1 is passed in e2 and then changes are made to the value present in e2 and then we

want to print the values of e1 then dravid will come in lower case

14. What will be the output of the program in 16-bit platform (under DOS)?

#include<stdio.h>

int main()

{

struct node

{

int data;

struct node *link;

};

struct node *p, *q;

p = (struct node *) malloc(sizeof(struct node));

q = (struct node *) malloc(sizeof(struct node));

Page 180: EXPRESSIONS - Google Groups

DURGA SOFTAWARE SOLUTIONS

CRT-C Language

DURGA SOFTWARE SOLUTIONS, 23/3RT, 2nd Floor. Opp: Reebok Shoe Room, Near Andhra Bank S.R Nagar, Hyderabad. Cell: 9246212143, Ph: 040-64512786 Page 180

printf("%d, %d\n", sizeof(p), sizeof(q));

return 0;

}

A. 2, 2 B. 8, 8

C. 5, 5 D. 4, 4

Answer & Explanation

Answer: Option A

Explanation:

Under 16 bit DOS the size of any pointer is 2 bytes.

15. What will be the output of the program ?

#include<stdio.h>

int main()

{

struct byte

{

int one:1;

};

struct byte var = {1};

printf("%d\n", var.one);

return 0;

}

[A]. 1 [B]. -1

[C]. 0 [D]. Error

Answer: Option B

Explanation:

If you store 1 in 1-bit field:

The left most bit is 1, so the system will treat the value as negative number.

The 2's complement method is used by the system to handle the negative values.

Therefore, the data stored is 1. The 2's complement of 1 is also 1 (negative).

Therefore -1 is printed.

11. What will be the output of the program ?

#include<stdio.h>

int main()

{

Page 181: EXPRESSIONS - Google Groups

DURGA SOFTAWARE SOLUTIONS

CRT-C Language

DURGA SOFTWARE SOLUTIONS, 23/3RT, 2nd Floor. Opp: Reebok Shoe Room, Near Andhra Bank S.R Nagar, Hyderabad. Cell: 9246212143, Ph: 040-64512786 Page 181

enum days {MON=-1, TUE, WED=6, THU, FRI, SAT};

printf("%d, %d, %d, %d, %d, %d\n", ++MON, TUE, WED, THU, FRI, SAT);

return 0;

}

A. -1, 0, 1, 2, 3, 4 B. Error:L value required

C. 0, 1, 6, 3, 4, 5 D. 0, 0, 6, 7, 8, 9

Answer & Explanation

Answer: Option B

Explanation:

Because ++ or -- cannot be done on enum value. Because these are treated as constants

12. What will be the output of the program ?

#include<stdio.h>

struct course

{

int courseno;

char coursename[25];

};

int main()

{

struct course c[] = { {102, "Java"},

{103, "PHP"},

{104, "DotNet"} };

printf("%d", c[1].courseno);

printf("%s\n", (*(c+2)).coursename);

return 0;

}

[A]. 103 Dotnet

[B]. 102 Java

[C]. 103 PHP [D]. 104 DotNet

Answer: Option A

Explanation:

When you do c[1].courseno it will print the 'c[1]' array 2nd variable ie(2nd

index) 103 then

(*(c+2)).coursename it will go into c[2] array's coursename contents ie DOTNET

Page 182: EXPRESSIONS - Google Groups

DURGA SOFTAWARE SOLUTIONS

CRT-C Language

DURGA SOFTWARE SOLUTIONS, 23/3RT, 2nd Floor. Opp: Reebok Shoe Room, Near Andhra Bank S.R Nagar, Hyderabad. Cell: 9246212143, Ph: 040-64512786 Page 182

13. What will be the output of the program ?

#include<stdio.h>

int main()

{

enum value{VAL1=0, VAL2, VAL3, VAL4, VAL5} var;

printf("%d\n", sizeof(var));

return 0;

}

[A]. 1 [B]. 2

[C]. 4 [D]. 10

Answer: Option B

Explanation:

If we run this program in DOS (compiled with Turbo C), it will show the output as 2. Because it

is a 16-bit platform. If you compile in a 32-bit platform like Linux (compiled with GCC

compiler), it will show 4 as the output.

14. Point out the error in the program?

struct employee

{

int ecode;

struct employee *e;

};

A. Error: in structure declaration

B. Linker Error

C. No Error

D. None of above

Answer & Explanation

Answer: Option C

Explanation:

This type of declaration is called as self-referential structure. Here *e is pointer to a struct

employee.

15. Point out the error in the program?

Page 183: EXPRESSIONS - Google Groups

DURGA SOFTAWARE SOLUTIONS

CRT-C Language

DURGA SOFTWARE SOLUTIONS, 23/3RT, 2nd Floor. Opp: Reebok Shoe Room, Near Andhra Bank S.R Nagar, Hyderabad. Cell: 9246212143, Ph: 040-64512786 Page 183

typedef struct smalldata mystruct;

struct smalldata

{

int x;

mystruct *b;

};

A. Error: in structure declaration

B. Linker Error

C. No Error

D. None of above

Answer & Explanation

Answer: Option C

Explanation:

Here the type name mystruct is known at the point of declaring the structure, as it is already

defined.

16. Point out the error in the program?

#include<stdio.h>

int main()

{

struct a

{

float category:5;

char scheme:4;

};

printf("size=%d", sizeof(struct a));

return 0;

}

A. Error: invalid structure member in printf

B. Error in this float category:5; statement

C. No error

D. None of above

Answer & Explanation

Answer: Option B

Explanation:

Bit field type must be signed int or unsigned int.

The char type: char scheme:2; is also a valid statement.

Page 184: EXPRESSIONS - Google Groups

DURGA SOFTAWARE SOLUTIONS

CRT-C Language

DURGA SOFTWARE SOLUTIONS, 23/3RT, 2nd Floor. Opp: Reebok Shoe Room, Near Andhra Bank S.R Nagar, Hyderabad. Cell: 9246212143, Ph: 040-64512786 Page 184

17. Point out the error in the program?

struct employee

{

int ecode;

struct employee e;

};

A. Error: in structure declaration

B. Linker Error

C. No Error

D. None of above

Answer & Explanation

Answer: Option A

Explanation:

The structure employee contains a member e of the same type.(i.e) struct employee. At this stage

compiler does not know the size of structure.

18.Point out the error in the program?

#include<stdio.h>

int main()

{

struct emp

{

char name[20];

float sal;

};

struct emp e[10];

int i;

for(i=0; i<=9; i++)

scanf("%s %f", e[i].name, &e[i].sal);

return 0;

}

A. Error: invalid structure member

B. Error: Floating point formats not linked

C. No error

D. None of above

Answer & Explanation

Answer: Option B

Page 185: EXPRESSIONS - Google Groups

DURGA SOFTAWARE SOLUTIONS

CRT-C Language

DURGA SOFTWARE SOLUTIONS, 23/3RT, 2nd Floor. Opp: Reebok Shoe Room, Near Andhra Bank S.R Nagar, Hyderabad. Cell: 9246212143, Ph: 040-64512786 Page 185

Explanation:

At run time it will show an error then program will be terminated.

Sample output: Turbo C (Windows)

c:\>myprogram

Sample

12.123

scanf : floating point formats not linked

Abnormal program termination

In order to remove error add following code in the program

void linkfloat()

{

float a=0,*b;

b=&a;

a=*b;

}

19. Point out the error in the program?

#include<stdio.h>

int main()

{

struct bits

{

int i:40;

}bit;

printf("%d\n", sizeof(bit));

return 0;

}

A. 4

B. 2

C. Error: Bit field too large

D. Error: Invalid member access in structure

Answer & Explanation

Answer: Option C

Explanation

Page 186: EXPRESSIONS - Google Groups

DURGA SOFTAWARE SOLUTIONS

CRT-C Language

DURGA SOFTWARE SOLUTIONS, 23/3RT, 2nd Floor. Opp: Reebok Shoe Room, Near Andhra Bank S.R Nagar, Hyderabad. Cell: 9246212143, Ph: 040-64512786 Page 186

The width of int is 4 bytes (32 bits) or 2 bytes (16 bits) depending upon the machine, so the

allocation for int is upto 32 bits. The declaration int i:40; exceeds the width of int so the compiler

generates the error:width of 'i' exceeds its type.

20. Point out the error in the program?

#include<stdio.h>

int main()

{

union a

{

int i;

char ch[2];

};

union a z1 = {512};

union a z2 = {0, 2};

return 0;

}

A. Error: invalid union declaration

B. Error: in Initializing z2

C. No error

D. None of above

Answer & Explanation

Answer: Option B

Explanation:

In union at a time, only one variable can be initialised.. so union a z2={0,2} is an error.

21. Point out the error in the program?

#include<stdio.h>

int main()

{

struct emp

{

char name[25];

int age;

float bs;

};

struct emp e;

e.name = "Durga";

e.age = 25;

Page 187: EXPRESSIONS - Google Groups

DURGA SOFTAWARE SOLUTIONS

CRT-C Language

DURGA SOFTWARE SOLUTIONS, 23/3RT, 2nd Floor. Opp: Reebok Shoe Room, Near Andhra Bank S.R Nagar, Hyderabad. Cell: 9246212143, Ph: 040-64512786 Page 187

printf("%s %d\n", e.name, e.age);

return 0;

}

A. Error: Lvalue required/incompatible types in assignment

B. Error: invalid constant expression

C. Error: Rvalue required

D. No error, Output: Durga 25

Answer & Explanation

Answer: Option A

Explanation:

We cannot assign a string to a struct variable like e.name = "Durga"; in C.

We have to use strcpy(char *dest, const char *source) function to assign a string.

Ex: strcpy(e.name, "Durga");

22. A union cannot be nested in a structure

[A]. True [B]. False

Answer: Option B

Explanation

The below code is legal

struct emp

{

int z;

union fac

{

int a;

};

};

23. If a char is 1 byte wide, an integer is 2 bytes wide and a long integer is 4 bytes wide then will

the following structure always occupy 7 bytes?

struct ex

{

char ch;

int i;

long int a;

};

Page 188: EXPRESSIONS - Google Groups

DURGA SOFTAWARE SOLUTIONS

CRT-C Language

DURGA SOFTWARE SOLUTIONS, 23/3RT, 2nd Floor. Opp: Reebok Shoe Room, Near Andhra Bank S.R Nagar, Hyderabad. Cell: 9246212143, Ph: 040-64512786 Page 188

A. Yes B. No

Answer & Explanation

Answer: Option B

Explanation:

A compiler may leave holes in structures by padding the first char in the structure with another

byte just to ensures that the integer that follows is stored at an location. Also, there might be

2extra bytes after the integer to ensure that the long integer is stored at an address, which is

multiple of 4. Such alignment is done by machines to improve the efficiency of accessing values.

Page 189: EXPRESSIONS - Google Groups

DURGA SOFTAWARE SOLUTIONS

CRT-C Language

DURGA SOFTWARE SOLUTIONS, 23/3RT, 2nd Floor. Opp: Reebok Shoe Room, Near Andhra Bank S.R Nagar, Hyderabad. Cell: 9246212143, Ph: 040-64512786 Page 189

Typedef

1.In the following code, the P2 is Integer Pointer or Integer?

typedef int *ptr;

ptr p1, p2;

A. Integer B. Integer pointer

C. Error in declaration D. None of above

Answer & Explanation

Answer: Option B

Explanation:

Here ptr is of int * type so ptr is alias to int *. P1,p2 are of ptr type so p1,p2 are int * type. Ie pte

is integer pointer or pointer to an integer.

2. What will be the output of the program?

#include<stdio.h>

int main()

{

typedef int arr[5];

arr iarr = {1, 2, 3, 4, 5};

int i;

for(i=0; i<=4; i++)

printf("%d,", iarr[i]);

return 0;

}

[A]. 1, 2, 3, 4

[B]. 1, 2, 3, 4, 5,

[C]. No output

[D]. Error: Cannot use typedef with an array

Answer: Option B

Explanation:

Typedef can be used even for arryas also. Arr is alias to int[5] so irr is integer array

arr iarr = {1, 2, 3, 4, 5}; is treated as

int iarr[5]={1,2,3,4,5};

3.Will the following code compile

Page 190: EXPRESSIONS - Google Groups

DURGA SOFTAWARE SOLUTIONS

CRT-C Language

DURGA SOFTWARE SOLUTIONS, 23/3RT, 2nd Floor. Opp: Reebok Shoe Room, Near Andhra Bank S.R Nagar, Hyderabad. Cell: 9246212143, Ph: 040-64512786 Page 190

#define max 5

#define int arr1[max]

main()

{

typedef char arr2[max];

arr1 list={0,1,2,3,4};

arr2 name="name";

printf("%d %s",list[0],name);

}

A. Yes B. No

Answer:

B. No

Compiler error (in the line arr1 list = {0,1,2,3,4})

Explanation:

arr2 is declared of type array of size 5 of characters. So it can be used to

declare the variable name of the type arr2. But it is not the case of arr1.

Hence an error.

Rule of Thumb:

#defines are used for textual replacement whereas typedefs are used for

declaring new types.

4. What will be the output of the program?

#include<stdio.h>

int main()

{

typedef float f;

f *fptr;

float fval = 900;

fptr = &fval;

printf("%f\n", *fptr);

return 0;

}

A. 9 B. 0

C. 900.000000 D. 90

Answer & Explanation

Answer: Option C

Explanation:

Page 191: EXPRESSIONS - Google Groups

DURGA SOFTAWARE SOLUTIONS

CRT-C Language

DURGA SOFTWARE SOLUTIONS, 23/3RT, 2nd Floor. Opp: Reebok Shoe Room, Near Andhra Bank S.R Nagar, Hyderabad. Cell: 9246212143, Ph: 040-64512786 Page 191

f is the new name of float. So fptr is of f* (ie float * type) so it can store float address of fval.

5. Is the following declaration acceptable?

typedef long no, *ptrtono;

no n;

ptrtono p;

A. Yes B. NO

Answer & Explanation

Answer: Option A

Here no is long type and ptrtono is of long* type and the declaration is correct.

6. typedef's have the advantage that they obey scope rules, that is they can be declared local to a

function or a block whereas #define's always have a global effect.

[A]. Yes

[B]. No

Answer: Option A

Explanation:

Lets us see simple example

Void main()

{

typedef int x;

#define a 100

}

Here x is having local scope.

Where as a is having global scope even though it is written in main()

7. What will be the output of the program?

#include<stdio.h>

int main()

{

int y=12;

const int x=y;

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

return 0;

}

A. 12 B. Garbage value

C. Error D. 0

Page 192: EXPRESSIONS - Google Groups

DURGA SOFTAWARE SOLUTIONS

CRT-C Language

DURGA SOFTWARE SOLUTIONS, 23/3RT, 2nd Floor. Opp: Reebok Shoe Room, Near Andhra Bank S.R Nagar, Hyderabad. Cell: 9246212143, Ph: 040-64512786 Page 192

Answer & Explanation

Answer: Option A

Explanation:

Step 1: int y=12; The variable 'y' is declared as an integer type and initialized to value "12".

Step 2: const int x=y; The constant variable 'x' is declared as an integer and it is initialized with

the variable 'y' value.

Step 3: printf("%d\n", x); It prints the value of variable 'x'.

Hence the output of the program is "12"

8. What will be the output of the program?

#include<stdio.h>

int main()

{

const int x=5;

const int *ptrx;

ptrx = &x;

*ptrx = 10;

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

return 0;

}

A. 5 B. 10

C. Error D. Garbage value

Answer & Explanation

Answer: Option C

Explanation:

Step 1: const int x=5; The constant variable x is declared as an integer data type and initialized

with value '5'.

Step 2: const int *ptrx; The constant variable ptrx is declared as an integer pointer.

Step 3: ptrx = &x; The address of the constant variable x is assigned to integer pointer variable

ptrx.

Page 193: EXPRESSIONS - Google Groups

DURGA SOFTAWARE SOLUTIONS

CRT-C Language

DURGA SOFTWARE SOLUTIONS, 23/3RT, 2nd Floor. Opp: Reebok Shoe Room, Near Andhra Bank S.R Nagar, Hyderabad. Cell: 9246212143, Ph: 040-64512786 Page 193

Step 4: *ptrx = 10; Here we are indirectly trying to change the value of the constant vaiable x.

This will result in an error.

To change the value of const variable x we have to use *(int *)&x = 10;

9. What will be the output of the program?

#include<stdio.h>

int main()

{

const char *s = "";

char str[] = "Hello";

s = str;

while(*s)

printf("%c", *s++);

return 0;

}

A. Error B. H

C. Hello D. Hel

Answer & Explanation

Answer: Option C

Explanation:

Step 1: const char *s = ""; The constant variable s is declared as an pointer to an array of

characters type and initialized with an empty string.

Step 2: char str[] = "Hello"; The variable str is declared as an array of charactrers type and

initialized with a string "Hello".

Step 3: s = str; The value of the variable str is assigned to the variable s. Therefore str contains

the text "Hello".

Step 4: while(*s){ printf("%c", *s++); } Here the while loop got executed untill the value of the

variable s is available and it prints the each character of the variable s.

Hence the output of the program is "Hello".

10. What will be the output of the program?

#include<stdio.h>

int get();

int main()

Page 194: EXPRESSIONS - Google Groups

DURGA SOFTAWARE SOLUTIONS

CRT-C Language

DURGA SOFTWARE SOLUTIONS, 23/3RT, 2nd Floor. Opp: Reebok Shoe Room, Near Andhra Bank S.R Nagar, Hyderabad. Cell: 9246212143, Ph: 040-64512786 Page 194

{

const int x = get();

printf("%d", x);

return 0;

}

int get()

{

return 2;

}

A. Garbage value B. Error

C. 2 D. 0

Answer & Explanation

Answer: Option C

Explanation:

Step 1: int get(); This is the function prototype for the funtion get(), it tells the compiler returns

an integer value and accept no parameters.

Step 2: const int x = get(); The constant variable x is declared as an integer data type and

initialized with the value "2".

The function get() returns the value "2".

Step 3: printf("%d", x); It prints the value of the variable x.

Hence the output of the program is "2".

11. What will be the output of the program (in Turbo C)?

#include<stdio.h>

int fun(int *f)

{

*f = 100;

return 0;

}

int main()

{

const int arr[5] = {1, 2, 3, 4, 5};

printf("Before modification arr[3] = %d", arr[3]);

fun(&arr[3]);

printf("\nAfter modification arr[3] = %d", arr[3]);

return 0;

}

Page 195: EXPRESSIONS - Google Groups

DURGA SOFTAWARE SOLUTIONS

CRT-C Language

DURGA SOFTWARE SOLUTIONS, 23/3RT, 2nd Floor. Opp: Reebok Shoe Room, Near Andhra Bank S.R Nagar, Hyderabad. Cell: 9246212143, Ph: 040-64512786 Page 195

A.

Before modification arr[3] = 4

After modification arr[3] = 100

B. Error: cannot convert parameter 1 from const int * to int *

C. Error: Invalid parameter

D.

Before modification arr[3] = 4

After modification arr[3] = 4

Answer & Explanation

Answer: Option A

Explanation:

Step 1: const int arr[5] = {1, 2, 3, 4, 5}; The constant variable arr is declared as an integer array

and initialized to

arr[0] = 1, arr[1] = 2, arr[2] = 3, arr[3] = 4, arr[4] = 5

Step 2: printf("Before modification arr[3] = %d", arr[3]); It prints the value of arr[3] (ie. 4).

Step 3: fun(&arr[3]); The memory location of the arr[3] is passed to fun() and arr[3] value is

modified to 100.

A const variable can be indirectly modified by a pointer.

Step 4: printf("After modification arr[3] = %d", arr[3]); It prints the value of arr[3] (ie. 100).

Hence the output of the program is

Before modification arr[3] = 4

After modification arr[3] = 100

Page 196: EXPRESSIONS - Google Groups

DURGA SOFTAWARE SOLUTIONS

CRT-C Language

DURGA SOFTWARE SOLUTIONS, 23/3RT, 2nd Floor. Opp: Reebok Shoe Room, Near Andhra Bank S.R Nagar, Hyderabad. Cell: 9246212143, Ph: 040-64512786 Page 196

Preprocessor 1. #define square(x) x*x

void main()

{

int i;

i = 64/square(4);

printf("%d",i);

}

A. 64 B.4 C. 16 D. error

Answer:

64

Explanation:

the macro call square(4) will substituted by 4*4 so the expression becomes i =64/4*4 . Since /

and * has equal priority the expression will be evaluated as (64/4)*4 i.e. 16*4= 64

2. What will the SWAP macro in the following program be expanded to on preprocessing? will

the code compile?

#include<stdio.h>

#define SWAP(a, b, c)(c t; t=a, a=b, b=t)

int main()

{

int x=10, y=20;

SWAP(x, y, int);

printf("%d %d\n", x, y);

return 0;

}

A. It compiles

B. Compiles with an warning

C. Not compile

D. Compiles and print nothing

Answer & Explanation

Answer: Option C

Explanation:

The code won't compile since declaration of t cannot occur within parenthesis.

3. #define int char

void main()

{

int i=65;

Page 197: EXPRESSIONS - Google Groups

DURGA SOFTAWARE SOLUTIONS

CRT-C Language

DURGA SOFTWARE SOLUTIONS, 23/3RT, 2nd Floor. Opp: Reebok Shoe Room, Near Andhra Bank S.R Nagar, Hyderabad. Cell: 9246212143, Ph: 040-64512786 Page 197

printf("sizeof(i)=%d",sizeof(i));

}

Answer:

sizeof(i)=1

A. 2 B. 1 C. 0 D. none of the above

Explanation:

Since the #define replaces the string int by the macro char

4.In which stage the following code

#include<conio.h>

gets replaced by the contents of the file conio.h

A. During editing B. During linking

C. During execution D.During preprocessing

Answer & Explanation

Answer: Option D

Explanation:

The preprocessor replaces the line #include <conio.h> with the system header file of that name.

More precisely, the entire text of the file 'conio.h' replaces the #include directive

4. Point out the error in the program

#include<stdio.h>

int main()

{

int i;

#if A

printf("Enter any number:");

scanf("%d", &i);

#elif B

printf("The number is odd");

return 0;

}

A. Error: unexpected end of file because there is no matching #endif

B. The number is odd

C. Garbage values

D. None of above

Answer & Explanation

Answer: Option A

Explanation:

Page 198: EXPRESSIONS - Google Groups

DURGA SOFTAWARE SOLUTIONS

CRT-C Language

DURGA SOFTWARE SOLUTIONS, 23/3RT, 2nd Floor. Opp: Reebok Shoe Room, Near Andhra Bank S.R Nagar, Hyderabad. Cell: 9246212143, Ph: 040-64512786 Page 198

The conditional macro #if must have an #endif. In this program there is no #endif statement

written.

5. #include <stdio.h>

#define a 10

main()

{

#define a 50

printf("%d",a);

}

A. 0 B.50 C.garbagevalue D.error

Answer:

50

Explanation:

The preprocessor directives can be redefined anywhere in the program. So

the most recently assigned value will be taken.

6. #define clrscr() 100

void main()

{

clrscr();

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

}

A 100 B. 0 C.garbagevalue D.error

Answer:

100

Explanation:

Preprocessor executes as a seperate pass before the execution of the

compiler. So textual replacement of clrscr() to 100 occurs.The input program to compiler

looks like this :

main()

{

100;

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

}

Note:

100; is an executable statement but with no action. So it doesn't give any

problem

7.Will the following code compile

#define f(g,g2) g##g2

void main()

{

Page 199: EXPRESSIONS - Google Groups

DURGA SOFTAWARE SOLUTIONS

CRT-C Language

DURGA SOFTWARE SOLUTIONS, 23/3RT, 2nd Floor. Opp: Reebok Shoe Room, Near Andhra Bank S.R Nagar, Hyderabad. Cell: 9246212143, Ph: 040-64512786 Page 199

int var12=100;

printf("%d",f(var,12));

}

A. Yes B. No

Answer:

100

Explanation:

#define f(g,g2) g##g2

g##g2 means token pasting so it will become gg2

similarly f(var,12) will become var12

so printf(ā€œ%dā€,var12);give 100as output

8. Will the following code compile

void main()

{

char not;

not=!2;

printf("%d",not);

}

A. Yes B. No

Answer:

A.Yes

Output: 0

Explanation:

! is a logical operator. In C the value 0 is considered to be the boolean value

FALSE, and any non-zero value is considered to be the boolean value TRUE.

Here 2 is a non-zero value so TRUE. !TRUE is FALSE (0) so it prints 0.

9) #define FALSE -1

#define TRUE 1

#define NULL 0

main() {

if(NULL)

puts("NULL");

else if(FALSE)

puts("TRUE");

Page 200: EXPRESSIONS - Google Groups

DURGA SOFTAWARE SOLUTIONS

CRT-C Language

DURGA SOFTWARE SOLUTIONS, 23/3RT, 2nd Floor. Opp: Reebok Shoe Room, Near Andhra Bank S.R Nagar, Hyderabad. Cell: 9246212143, Ph: 040-64512786 Page 200

else

puts("FALSE");

}

A.TRUE B.FALSE C.NULL D.error

Answer:

A. TRUE

Explanation:

The input program to the compiler after processing by the preprocessor is,

main(){

if(0)

puts("NULL");

else if(-1)

puts("TRUE");

else

puts("FALSE");

}

Preprocessor doesn't replace the values given inside the double quotes. The

check by if condition is boolean value false so it goes to else. In second if -1

is boolean value true hence "TRUE" is printed.

Page 201: EXPRESSIONS - Google Groups

DURGA SOFTAWARE SOLUTIONS

CRT-C Language

DURGA SOFTWARE SOLUTIONS, 23/3RT, 2nd Floor. Opp: Reebok Shoe Room, Near Andhra Bank S.R Nagar, Hyderabad. Cell: 9246212143, Ph: 040-64512786 Page 201

Bitwise Operator

1. In which numbering system can the binary number 011111000101 be easily converted to?

A. Decimal system B. Hexadecimal system

C. Octal system D. No need to convert

Answer & Explanation

Answer: Option B

Explanation:

Hexadecimal system is better, because each 4-digit binary represents one Hexadecimal digit.

2. Which bitwise operator is suitable for turning off a particular bit in a number?

A. || operator B. & operator

C. && operator D. ! operator

Answer & Explanation

Answer: Option B

Explanation

Any bit AND(&) with 0 will give a zero .i.e. will turn that particular bit OFF.

3.Assunming, integer is 2 byte, What will be the output of the program?

#include<stdio.h>

int main()

{

printf("%x\n", -1>>1);

return 0;

}

A. ffff B. 0fff

C. 0000 D. fff0

Answer & Explanation

Answer: Option A

Explanation:

Negative numbers are treated with 2's complement method.

Page 202: EXPRESSIONS - Google Groups

DURGA SOFTAWARE SOLUTIONS

CRT-C Language

DURGA SOFTWARE SOLUTIONS, 23/3RT, 2nd Floor. Opp: Reebok Shoe Room, Near Andhra Bank S.R Nagar, Hyderabad. Cell: 9246212143, Ph: 040-64512786 Page 202

1's complement: Inverting the bits ( all 1s to 0s and all 0s to 1s)

2's complement: Adding 1 to the result of 1's complement.

Binary of 1(2byte) : 0000 0000 0000 0001

Representing -1:

1s complement of 1(2byte) : 1111 1111 1111 1110

Adding 1 to 1's comp. result : 1111 1111 1111 1111

Right shift 1bit(-1>>1): 1111 1111 1111 1111 (carry out 1)

Hexadecimal : f f f f

(Filled with 1s in the left side in the above step)

Note:

1. Fill with 1s in the left side for right shift for negative numbers.

2. Fill with 0s in the right side for left shift for negative numbers.

3. Fill with 0s in the left side for right shift for positive numbers.

4. Fill with 0s in the right side for left shift for positive numbers.

4. If an unsigned int is 2 bytes wide then, What will be the output of the program ?

#include<stdio.h>

int main()

{

unsigned int m = 32;

printf("%x\n", ~m);

return 0;

}

A. ffff B. 0000

C. ffdf D. ddfd

Answer & Explanation

Answer: Option C

Explanation:

32 can be written as 0000 0000 0010 0000 in 2 bytes and complement operator convert this to

1111 1111 1101 1111 and it is printed with %x format hence option c.

5.If an unsigned int is 2 bytes wide then, What will be the output of the program ?

#include<stdio.h>

int main()

{

unsigned int a=0xffff;

~a;

Page 203: EXPRESSIONS - Google Groups

DURGA SOFTAWARE SOLUTIONS

CRT-C Language

DURGA SOFTWARE SOLUTIONS, 23/3RT, 2nd Floor. Opp: Reebok Shoe Room, Near Andhra Bank S.R Nagar, Hyderabad. Cell: 9246212143, Ph: 040-64512786 Page 203

printf("%x\n", a);

return 0;

}

A. ffff B. 0000

C. 00ff D. ddfd

Answer & Explanation

Answer: Option A

Explanation:

Here the modification done to a is not reassigned so a value is not affected.

6.What will be the output of the program?

#include<stdio.h>

int main()

{

unsigned char i = 0x80;

printf("%d\n", i<<1);

return 0;

}

A. 0 B. 256

C. 100 D. 80

Answer & Explanation

Answer: Option B

Explanation:

i = 0x80 = 00000000 10000000 in binary form.

After i<<1 it becomes 00000001 00000000. Its decimal equivallent is 256.

7. What will be the output of the program?

#define P printf("%d\n", -1^~0);

#define M(P) int main()\

{\

P\

return 0;\

}

M(P)

[A]. 1 [B]. 0

[C]. -1 [D]. 2

Page 204: EXPRESSIONS - Google Groups

DURGA SOFTAWARE SOLUTIONS

CRT-C Language

DURGA SOFTWARE SOLUTIONS, 23/3RT, 2nd Floor. Opp: Reebok Shoe Room, Near Andhra Bank S.R Nagar, Hyderabad. Cell: 9246212143, Ph: 040-64512786 Page 204

Answer: Option B

Explanation:

After the First macro function executed

#define P printf("%d\n", -1^~0);

#define M(P) int main()\

{\

P\

return 0;\

}

M(printf("%d\n", -1^~0);)

After the second Macro function executed

#define P printf("%d\n", -1^~0);

#define M(P) int main()\

{\

P\

return 0;\

}

int main()

{

printf("%d\n", -1^~0);

return 0;

}

~0 is -1

-1^-1 is 0

8. Which of the following statements are correct about the program?

#include<stdio.h>

int main()

{

unsigned int num;

int i;

scanf("%u", &num);

for(i=0; i&lt16; i++)

{

printf("%d", (num<<i & 1<<15)?1:0);

}

return 0;

}

A. It prints all even bits from num

B. It prints all odd bits from num

Page 205: EXPRESSIONS - Google Groups

DURGA SOFTAWARE SOLUTIONS

CRT-C Language

DURGA SOFTWARE SOLUTIONS, 23/3RT, 2nd Floor. Opp: Reebok Shoe Room, Near Andhra Bank S.R Nagar, Hyderabad. Cell: 9246212143, Ph: 040-64512786 Page 205

C. It prints binary equivalent num

D. Error

Answer & Explanation

Answer: Option C

Explanation:

If we give input 4, it will print 00000000 00000100 ;

If we give input 3, it will print 00000000 00000011 ;

If we give input 511, it will print 00000001 11111111 ;

9.w hich of the following statements are correct about the program?

#include<stdio.h>

int main()

{

unsigned int num;

int c=0;

scanf("%u", &num);

for(;num;num>>=1)

{

if(num & 1)

c++;

}

printf("%d", c);

return 0;

}

A. It counts the number of bits that are ON (1) in the number num.

B. It counts the number of bits that are OFF (0) in the number num.

C. It sets all bits in the number num to 1

D. Error

Answer & Explanation

Answer: Option A

Explanation:

If we give input 4, it will print 1.

Binary-4 == 00000000 00000100 ; Total number of bits = 1.

If we give input 3, it will print 2.

Binary-3 == 00000000 00000011 ; Total number of bits = 2.

If we give input 511, it will print 9.

Binary-511 == 00000001 11111111 ; Total number of bits = 9.

Page 206: EXPRESSIONS - Google Groups

DURGA SOFTAWARE SOLUTIONS

CRT-C Language

DURGA SOFTWARE SOLUTIONS, 23/3RT, 2nd Floor. Opp: Reebok Shoe Room, Near Andhra Bank S.R Nagar, Hyderabad. Cell: 9246212143, Ph: 040-64512786 Page 206

Command Line Arguments

1.According to ANSI specifications which is the correct way of declaring main when it receives

command-line arguments?

A. int main(int argc, char *argv[]){}

B.

int main(argc, argv){

int argc; char *argv;}

C.

int main()

{

int argc; char *argv;

}

D. None of above

Answer & Explanation

Answer: Option A

2. The maximum combined length of the command-line arguments including the spaces between

adjacent arguments is

A. 128 characters

B. 256 characters

C. 64 characters

D. It may vary from one operating system to another

Answer & Explanation

Answer: Option D

Explanation:

The command promt is based on OS.

3. What will be the output of the program (my.c) given below if it is executed from the command

line?

cmd> my one two three

/* my.c */

#include<stdio.h>

int main(int argc, char **argv)

{

printf("%c\n", **++argv);

Page 207: EXPRESSIONS - Google Groups

DURGA SOFTAWARE SOLUTIONS

CRT-C Language

DURGA SOFTWARE SOLUTIONS, 23/3RT, 2nd Floor. Opp: Reebok Shoe Room, Near Andhra Bank S.R Nagar, Hyderabad. Cell: 9246212143, Ph: 040-64512786 Page 207

return 0;

}

A. my one two three B. my one

C. o D. two

Answer & Explanation

Answer: Option C

Explanation

argv[0] = my

argv[1] = one

So ++argv=> argv[1]. That is it points to 2nd

word ie one

**++argv gives first char in the second word

4. What will be the output of the program (sam.c) given below if it is executed from the

command line?

cmd> sam 1 2 3

/* sam.c */

#include<stdio.h>

int main(int argc, char *argv[])

{

int j;

j = argv[1] + argv[2] + argv[3];

printf("%d", j);

return 0;

}

[A]. 6 [B]. sam 6

[C]. Error

[D]. Garbage value

Answer: Option C

Explanation:

Here argv[1],argv[2],argv[3] are strings so we cannot add. use atoi() to convert string to int

As shown below

atoi(argv[1])+atoi(argv[2])

5. What will be the output of the program (sam.c) given below if it is executed from the

command line?

cmd> sam "*.c"

Page 208: EXPRESSIONS - Google Groups

DURGA SOFTAWARE SOLUTIONS

CRT-C Language

DURGA SOFTWARE SOLUTIONS, 23/3RT, 2nd Floor. Opp: Reebok Shoe Room, Near Andhra Bank S.R Nagar, Hyderabad. Cell: 9246212143, Ph: 040-64512786 Page 208

/* sam.c */

#include<stdio.h>

int main(int argc, int *argv)

{

int i;

for(i=1; i<argc; i++)

printf("%s\n", argv[i]);

return 0;

}

A. *.c

B. "*.c"

C. sam *.c

D. List of all files and folders in the current directory

Answer & Explanation

Answer: Option A

*.c is the 1st argument so it is printed on the screen

6.What will be the output of the program if it is executed like below?

cmd> sam

/* sam.c */

#include<stdio.h>

int main(int argc, char **argv)

{

printf("%s\n", argv[argc-1]);

return 0;

}

A. 0 B. sam

C. samp D. No output

Answer & Explanation

Answer: Option B

Explanation:

argc by default contain 1. So argv[argc-1] is taken as argv[0] the 1st argument is by default the

program name so the output is sam

7. What will be the output of the program (sam.c) given below if it is executed from the

command line?

cmd> sam one two three

/* sam.c */

Page 209: EXPRESSIONS - Google Groups

DURGA SOFTAWARE SOLUTIONS

CRT-C Language

DURGA SOFTWARE SOLUTIONS, 23/3RT, 2nd Floor. Opp: Reebok Shoe Room, Near Andhra Bank S.R Nagar, Hyderabad. Cell: 9246212143, Ph: 040-64512786 Page 209

#include<stdio.h>

int main(int argc, char *argv[])

{

int i=0;

i+=strlen(argv[1]);

while(i>0)

{

printf("%c", argv[1][--i]);

}

return 0;

}

[A]. three two one [B]. owt

[C]. eno

[D]. eerht

Answer: Option C

Explanation:

Argv[1] contains one

i=i+strlen(argv[1]); //i=0+3;

while(i>0) //while(3>0)

argv[1][--i] //argv[1][3] =>e and

i value decremented to 2[--i]

argv[1][2]=>n

and i=1[--i]

argv[1][1]=>o

o/p:eno

8. Every time we supply new set of values to the program at command prompt. we need to

recompile the program.

[A]. True [B]. False

Answer: Option B

Explanation:

The command line arguments are entered after compilation and execution we are not changing

the program code so there is no need to recompile .

9. Even if integer/float arguments are supplied at command prompt they are treated as strings.

A. True B. False

Page 210: EXPRESSIONS - Google Groups

DURGA SOFTAWARE SOLUTIONS

CRT-C Language

DURGA SOFTWARE SOLUTIONS, 23/3RT, 2nd Floor. Opp: Reebok Shoe Room, Near Andhra Bank S.R Nagar, Hyderabad. Cell: 9246212143, Ph: 040-64512786 Page 210

Answer & Explanation

Answer: Option A

Explanation:

The command line arguments are by default strings

As char*[]argv that is array of string addresses.