Conditional Statement


Q1.

Consider the following ANSI C program. #include < stdio.h > int main() { int i, j, count; count=0; i=0; for (j=-3; j < =3; j++) { if (( j > = 0) && (i++)) count = count + j; } count = count +i; printf("%d", count); return 0; }Which one of the following options is correct?
GateOverflow

Q2.

What is the output of tho following program? main(){ int x=2, y=5; if(x < y) return (x=x+y); else printf("z1"); printf("z2"); }
GateOverflow

Q3.

Assume A and B are non-zero positive integers. The following code segment: while(A!=B){ if(A > B) A -= B; else B -= A; } cout << A; // printing the value of A
GateOverflow

Q4.

Consider the following pseudocodex:=1; i:=1; while ( x \leq 500 ) begin x:=2^x; i:=i+1; end What is the value of i at the end of the pseudocode?
GateOverflow

Q5.

An unrestricted use of the "goto" statement is harmful because
GateOverflow

Q6.

An unrestricted use of the "go to" statement is harmful because of which of the following reason (s):
GateOverflow

Q7.

In the following Pascal program segment, what is the value of X after the execution of the program segment? X := -10; Y := 20; If X > Y then if X < 0 then X := abs(X) else X := 2*X;
GateOverflow

Q8.

Consider the C program below. #include < stdio.h > int *A, stkTop; int stkFunc(int opcode, int val) { static int size=0, stkTop=0; switch (opcode) { case -1: size = val; break; case 0: if (stkTop < size) A[stkTop++] = val; break; default: if (stkTop) return A[--stkTop]; } return -1; } int main() { int B[20]; A = B; stkTop = -1; stkFunc (-1, 10); stkFunc ( 0, 5); stkFunc ( 0, 10); printf ("%d\n", stkFunc(1, 0) + stkFunc(1, 0)); } The value printed by the above program is __________.
GateOverflow

Q9.

Let x be an integer which can take a value of 0 or 1. The statement if (x == 0) x = 1; else x = 0; is equivalent to which one of the following ?
GateOverflow

Q10.

Consider the following code segment: for (int k=0; k<20; k=k+2) { if (k % 3 == 1) system.out.print(k+ " "); } What is printed as a result of executing the code segment?
GateOverflow