Slideshow

Monday 25 February 2013


Q.51 What is the output of following statement?
for(i=1; i<4; i++)
printf(“%d”,(i%2) ? i : 2*i);
(A) 1 4 3 (B) 1 2 3
(C) 2 4 6 (D) 2 2 6

Ans: A
for i=1, (i%2) is true so the statement will print 1; for for i=2, (i%2) is false so the
statement will print 2*i=2*2=4; for for i=3, (i%2) is again true so the statement will
print 3; for i=4, the statement is out from the loop.

52 Which of the following statement is true about a function?
(A) An invoking function must pass arguments to the invoked function.
(B) Every function returns a value to the invoker.
AC05 Programming & Problem Solving Through ‘C’
AC06 Data Structures
11
(C) A function may contain more than one return statement.
(D) Every function must be defined in its own separate file.
Ans: A
An invoking function must pass arguments to the invoked function.
Q.53 What is the output of the following program?
main( )
{
int i=4, z=12;
if(i=5 || z>50)
printf(“hello”);
else
printf(“hye”);
}
(A) hello (B) hye
(C) syntax error (D) hellohye
Ans: A
i=5 will assign value 5 to i so the if statement (i=5||z>50) is true so “printf” statement
will print hello.
Q.54 For implementing recursive function the data structure used is:
(A) Queue (B) Stack
(C) Linked List (D) Tree
Ans: B
For implementing recursive function, stack is used as a data structure.
Q.55 The size of array int a[5]={1,2} is
(A) 4 (B) 12
(C) 10 (D) 6
Ans: C
The size of int array is 2*5=10 bytes as int takes 2 bytes of storage.
Q.56 Which of the following is not an escape sequence?
(A) \n (B) \r
(C) \’ (D) \p
Ans: D
\p is not an escape sequence.
Q.57 The output of the following statements is
char ch[6]={‘e’, ‘n’, ‘d’, ‘\0’, ‘p’};
printf(“%s”, ch);
(A) endp (B) end0p
(C) end (D) error
Ans: C
printf statement will print end because string is terminated at “\0” and in array after d,
we have null character.
AC05 Programming & Problem Solving Through ‘C’
AC06 Data Structures
12
Q.58 How many times the following code prints the string “hello”.
for(i=1; i<=1000; i++);
printf(“hello”);
(A) 1 (B) 1000
(C) Zero (D) Syntax error
Ans: A
The “for” loop is terminated by a semicolon so the next statement is execute that is
printing hello.
Q.59 Find the invalid identifiers from the following:-
(i) nA (ii) 2nd (iii) ROLL NO (iv) case
(A) (i), (ii) and (iv) (B) (i) and (iii)
(C) (ii), (iii) and (iv) (D) (ii), (i) and (iii)
Ans: C
Identifier cannot start with a digit; it cannot have a space and case is a keyword.
Q.60 The void type is used for
(A) Returning the value (B) creating generic pointers
(C) Creating functions (D) Avoid error
Ans: B
The void type is used to create generic pointers.
Q.61 The valid octal constants from the following
(i) 0245 (ii) 0387 (iii) 04.32 (iv) –0467
(A) (i) and (ii) (B) (iii) and (iv)
(C) (ii) and (iii) (D) (i) and (iv)
Ans: D
(i) and (iv) are valid octal constants.
Q.62 The variable that are declared outside all the functions are called ______.
(A) Local variable (B) Global variable
(C) Auto variable (D) None of the above
Ans: B
The variables that are declared outside all functions are called global variable.
Q.63 Consider the following statements:-
int x = 6, y=8, z, w;
y = x++;
z = ++x;
The value of x,y,z by calculating the above expressions are:-
(A) y=8, z=8, x=6 (B) y=6, x=8, z=8
(C) y=9, z=7, x=8 (D) y=7, x=8, z=7
Ans: B
y is assigned value of x that is 6, then x in incremented that is value of x=7, z is
assigned value of x after incrementing that is z =8 so value of x =8.
AC05 Programming & Problem Solving Through ‘C’
AC06 Data Structures
13
Q.64 To declare an array S that holds a 5-character string, you would write
(A) char S[5] (B) String S[5]
(C) char S[6] (D) String S[6]
Ans: A
A string is nothing but a char array.
Q.65 The function used to read a character from a file that has been opened in read mode is
(A) putc (B) getc
(C) getchar (D) putchar
Ans: B
getc is used to read a character from a file that has been opened in read mode.
Q.66 The function that allocates requested size of bytes and returns a pointer to the first
byte of the allocated space is -
(A) realloc (B) malloc
(C) calloc (D) none of the above
Ans: B
malloc allocates requested size of bytes and returns a pointer to the first byte of the
allocated space.

No comments:

Post a Comment