24-07-2014, 12:13 PM
TYPICAL QUESTIONS & ANSWERS
TYPICAL QUESTIONS & ANSWERS.pdf (Size: 1.37 MB / Downloads: 251)
What is the output of the following program?
main ( )
{ int x = 2, y = 5;
if (x < y) return (x = x+y); else printf (“z1”);
printf(“z2”);
}
(A) z2 (B) z1z2
© Compilation error (D) None of these
Ans: D
There is no compilation error but there will no output because function is returning a
value and if statement is true in this case.
Q.2 Choose the correct one
(A) Address operator can not be applied to register variables
(B) Address operator can be applied to register variables
© Use of register declaration will increase the execution time
(D) None of the above
Ans: D
A register access is much faster than a memory access, keeping the frequently
accessed variables in the register will lead to faster execution of programs.
Q.3 What is the following program doing?
main ()
{ int d = 1;
do
printf(“%d\n”, d++);
while (d < = 9);}
(A) Adding 9 integers (B) Adding integers from 1 to 9
© Displaying integers from 1 to 9 (D) None of these
Ans: C
d starting from 1 is incrementing one by one till d=9 so the printf statement is printing
numbers from 1 to 9.
Q.4 What is the output of the following program?
main ( )
{ extern int x;
x = 20;
printf(“\n%d”, x);
}
AC05 Programming & Problem Solving Through ‘C’
AC06 Data Structures
2
(A) 0 (B) 20
© error (D) garbage value
Ans: C
Output of the given program will be “Linker error-undefined symbol x”. External
variables are declared outside a function.
Q.5 If x is one dimensional array, then pick up the correct answer
(A) *(x + i) is same as &x[i] (B) *&x[i] is same as x + i
© *(x + i) is same as x[i] +1 (D) *(x + i) is same as *x[i]
Ans: A
num[i] is same as *(num+i)
Q.6 Consider the following declaration
int a, *b = &a, *c = &b;
The following program fragment
a = 4;
*c = 5;
(A) does not change the value of a (B) assigns address of c to a
© assigns the value of b to a (D) assigns 5 to a
Ans: D
The given statements assigns 5 to a
Q.7 Choose the correct answer
(A) enum variable can not be assigned new values
(B) enum variable can be compared
© enumeration feature increase the power of C
(D) None of the above
Ans: C
The enumerated data types give an opportunity to invent our own data typeand define
what value the variable of this data type can take.
Q.8 The content of file will be lost if it is opened in
(A) w mode (B) w+ mode
© a mode (D) a+ mode
Ans: A
When the mode is writing, the contents are deleted and the file is opened as a new file.
Q.9 Consider the following code segment:
int a[10], *p1, *p2;
p1 = &a[4];
p2 = &a[6];
Which of the following statements is incorrect w.r.t. pointers?
(A) p1 + 2 (B) p2 – 2
© p2 + p1 (D) p2 – p1
Ans: CAC05 Programming & Problem Solving Through ‘C’
AC06 Data Structures
3
Addition of two pointers is not allowed.
Q.10 The second expression (j – k) in the following expression will be evaluated
(i + 5) && (j – k)
(A) if expression (i + 5) is true.
(B) if expression (i + 5) is false.
© irrespective of whether (i + 5) is true or false.
(D) will not be evaluated in any case.
Ans: A
In a compound logical expression combined with &&, the second expression is
evaluated only if first is evaluated in true.
Q.11 In the for statement: for (exp1; exp2; exp3) { … }
where exp1, exp2 and exp3 are expressions. What is optional?
(A) None of the expressions is optional.
(B) Only exp1 is optional.
© Only exp1 and exp3 are optional.
(D) All the expressions are optional.
Ans: D
All the expressions are optional. For (; is a valid statement in C.
Consider the following code segment:
int a[10], *p1, *p2;
p1 = &a[4];
p2 = &a[6];
Which of the following statements is incorrect w.r.t. pointers?
(A) p1 + 2 (B) p2 – 2
© p2 + p1 (D) p2 – p1
Ans: CAC05 Programming & Problem Solving Through ‘C’
AC06 Data Structures
3
Addition of two pointers is not allowed.
Q.10 The second expression (j – k) in the following expression will be evaluated
(i + 5) && (j – k)
(A) if expression (i + 5) is true.
(B) if expression (i + 5) is false.
© irrespective of whether (i + 5) is true or false.
(D) will not be evaluated in any case.
Ans: A
In a compound logical expression combined with &&, the second expression is
evaluated only if first is evaluated in true.
Q.11 In the for statement: for (exp1; exp2; exp3) { … }
where exp1, exp2 and exp3 are expressions. What is optional?
(A) None of the expressions is optional.
(B) Only exp1 is optional.
© Only exp1 and exp3 are optional.
(D) All the expressions are optional.
Ans: D
All the expressions are optional. For (; is a valid statement in C.
Q.12 The output of the following code segment will be
char x = ‘B’;
switch (x) {
case ‘A’: printf(“a”);
case ‘B’: printf(“b”);
case ‘C’: printf(“c”);
}
(A) B (B) b
© BC (D) bc
Ans: D
Since there is no break statement, all the statement after case’B’ are executed.
Q.13 What will be the output of the following code segment?
main( ) {
char s[10];
strcpy(s, “abc”);
printf(“%d %d”, strlen(s), sizeof(s));