Machine-translated by Google. Questions are authored in English.
Top

Expressions Questions and Answers

11.

If 'i' is a variable, i++ denotes

Exam Year(s)

UGC NET - 2013,

Answer: B

The statement i++ means that i is incremented once. In C the post-increment operator adds 1 to the variable after its current value has been used in the expression. It does not add 2, so (A) and (C) are wrong, and it has nothing to do with multiplication, which rules out (D). The pre-increment form ++i also adds exactly one, and the difference between the two forms is only the moment at which the new value becomes visible in the surrounding expression.

Please log in or register to report this question.

12.

C program is as follows : The result of the program is

int i;      /*...declare integer i...*/
i=10;       /*...set i to 10 ...*/
i=i+'A';    /*...add character A...*/
            /*...to integer i...*/
print f ("i=%d", i);

Exam Year(s)

UGC NET - 2013,

Answer: D

The program prints i = 75, the fourth option. The character constant 'A' has the ASCII value 65, so adding it to the integer gives

\[i = 10 + 65 = 75\]

The output is "i=75". The value 55 would arise if 'A' were taken as 45, and 51 and 71 do not correspond to the ASCII value of any such constant. The compiler converts the character to its integer code before the addition, which is why a letter can be added to an int in C, and the format %d then prints that integer sum and not a letter.

Please log in or register to report this question.

13.

Consider the following conditional expression

z = (x \gt y) ? x : y;

if x = 2 and y = 8, the value of z is

Exam Year(s)

UGC NET - 2013,

Answer: B

The value of z is 8, the second option. The conditional expression returns x if the condition (x > y) is true and y otherwise. With x = 2 and y = 8 the condition \(2 \gt 8\) is false, so z takes the value of y, which is 8.

The value 2 would be the result if the condition were true, and 6 and 10 are the difference and the sum of the two numbers, which the expression does not calculate.

Please log in or register to report this question.

14.

When the following code is executed what will be the value of x and y ? int x = 1, y = 0; y = x++;

Exam Year(s)

UGC NET - 2013,

Answer: A

After int x = 1, y = 0; the statement y = x++; uses post-increment, so the value of x is first assigned to y and then x is increased. y therefore takes the old value 1, and x becomes 2. The pair (x, y) is (2, 1), option (A). Option (B) 2,2 would need the pre-increment form y = ++x. Option (C) 1,1 forgets that x is increased at all, and option (D) 1,2 swaps the two values. The rule to remember is that in x++ the old value is the value of the expression, and the side effect of increment happens afterwards.

Please log in or register to report this question.

15.

What is the result of the expression (1&2)+(3/4) ?

Exam Year(s)

UGC NET - 2013,

Answer: D

The expression (1&2)+(3/4) gives 0, option (D). In the C style operators, & is the bitwise AND: 1 is 01 in binary and 2 is 10, so their bitwise AND is 00, that is 0. The division 3/4 is integer division, which truncates the fraction 0.75 to 0. The sum is 0 + 0 = 0. Option (A) 1 would result if 3/4 were read as 1, option (B) 2 if the AND were read as OR or a sum, and option (C) 3 if both operands of the sum were counted wrongly. The value follows from reading the first term as bitwise and the second as integer division.

Please log in or register to report this question.

16.

Refer the points as listed below :

(a) What are the operator precedence rules ?
(b) What are the operator associativity rules ?
(c) What is the order of operand evaluation ?
(d) Are there restrictions on operand evaluation side effects ?
Which of the above must be considered as primary design issues for arithmetic expressions ?

Exam Year(s)

UGC NET - 2013,

Answer: D

All four are primary design issues for arithmetic expressions, so option (D) is the answer. The language designer has to decide the operator precedence rules (a), the operator associativity rules (b), the order of operand evaluation (c), and whether there are restrictions on operand evaluation side effects (d), since the value of an expression such as a + f(a) can depend on them.

Options (A), (B) and (C) each leave out one of the four issues, so they are incomplete.

Please log in or register to report this question.

17.

Sequence of operators according to the priority

1. '/' 2. '+'
3. '*' 4. '-' The correct sequence is

Exam Year(s)

UGC NET - 2014,

Answer: D

The correct sequence is 3, 1, 2 and 4: multiplication, division, addition, subtraction. In C the operators * and / have the same precedence and rank above + and -, which also share a level. Listing them from highest priority gives * and / first, then + and -.


The sequence 1, 2, 3, 4 puts addition above multiplication, and 2, 3, 4, 1 and 3, 4, 1, 2 put an additive operator ahead of division. All three contradict the usual precedence.

Please log in or register to report this question.

18.

What is the output of this C code?    

void main()
    {
        int x = 4;
        int *p = &x;
        int *k = p++;
        int r = p - k;
        printf("%d", r);
    }

 

Answer: C

Correct answer: 1

Pointer subtraction returns the number of elements between the two pointers, not the number of bytes. k holds the value p had before the increment, and p++ moved p on by one int, so p - k is 1. The compiler divides the 4-byte gap by sizeof(int) for you.

Please log in or register to report this question.

19.

What is the output of this C code?    

int main()
    {
        int i = -5;
        int k = i %4;
        printf("%d\n", k);
    }

 

Answer: B

Correct answer: -1

In C the result of % takes the sign of the dividend, and the language requires that (a/b)*b + a%b == a. Since -5 / 4 truncates toward zero to \(-1\), we need \(-1 \times 4 + r = -5\), giving \(r = -1\). So the program prints -1.

Please log in or register to report this question.

20.

What is the value of the below assignment expression
      (x = foo()) in the statement (x = foo()) != 1, considering that foo() returns 2?

Answer: A

Correct answer: 2

The value of an assignment expression is the value assigned. foo() returns 2, so x becomes 2 and the expression (x = foo()) itself has the value 2. That value is then what the surrounding != 1 compares against - and the comparison, being a separate expression, would yield 1.

Please log in or register to report this question.

Loading…

Other Subjects

Tags: Expressions Questions and Answers || Expressions MCQ Questions and Answers || Expressions GK Questions and Answers || Expressions GK MCQ Questions || Expressions Multiple Choice Questions and Answers || Expressions GK || GK on Expressions || C Programming Questions and Answers || C Programming MCQ Questions and Answers || C Programming GK Questions and Answers || GK on C Programming