221. Which of the following gives the memory address of the first element in array foo, an array with 100 elements?
A. foo[0];
B. foo;
C. &foo;
D. foo[1];

Answer : b

222. Which is an error.
a.Int *p[3]
b.Int (*p)[3]
c.(Int *)(int ,int)
d.Int (*p[3])
e.Int *(p[3])

Answer :

223. Which of the following is a static string?
A. Static String
B. "Static String"
C. 'Static String'
D. char string[100];

Answer :

224. What character ends all strings?
A. '.'
B. ' '
C. '\0'
D. '\n'

Answer :c
225. Which of the following reads in a string named x with one hundred characters?
A fgets(x, 101, stdin);
B. fgets(x, 100, stdin);
C. readline(x, 100, '\n');

D. read(x);

Answer :a

226. Which of the following functions compares two strings?A. compare();B. stringcompare();C. cmp();D. strcmp();

Answer :d

227. Which of the following adds one string to the end of another?A. append();

B. stringadd();C. strcat();D. stradd();

Answer :c

228. Which header file do you need to include to use typecasting?
A. iostream.h
B. ctype.h
C. math.h
D. None

Answer :d

229. Which is a valid typecast?
A. a(char);
B. char:a;
C. (char)a;
D. to(char, a);

Answer :c

229. Why can typecasting be dangerous?
A. Some conversions are not defined, such as char to int.
B. You might permanently change the value of the variable.
C. You might temporarily lose part of the data - such as truncating a float when typecasting to an int.
D. There are no dangers.

Answer :c

230. Which is a good use for typecasting?
A. To allow division of two integers to return a decimal value.
B. To allow your program to use nothing but integers.
C. To change the return type of a function.
D. To swap variables rapidly.

Answer :a

231. Which conversion is not possible?A. int to floatB. float to intC. char to floatD. All are possible

Answer :d

232. What variables stores the number of arguments to a program?
A. argc
B. argv
C count
D. arglen

Answer :a

233. What is argv[0]?
A. The number of arguments to the program
B. The name of the program
C. The first argument to the program
D. This syntax is illegal

Answer : b

234. What type is argv?
A. char *
B. int
C. char **
D. It's not a variable

Answer :c

235. In what order do the two command line variables appear in the definition of main?
A. Count then argument array
B. Argument array then count
C. They don't appear in the definition of main
D. There is only one argument.

Answer :a

235. What does the argument count variable store?
A. the number of arguments
B. the number of arguments plus one
C. the number of arguments minus one

D. The total size of the argument array

Answer :c

236. Which of the following about the following two declaration is true
i ) int *F()
ii) int (*F)()
Choice :

a) Both are identical
b) The first is a correct declaration and the second is wrong
c) The first declaraion is a function returning a pointer to an integer and the second is a pointer to function returning int
d) Both are different ways of declarin pointer to a function

Answer : c)

237. Two variable cannot have the same name in
a)function b) block c) file d)--- C Section

Answer :

238. Find the output for the following C program
f=(x>y)?x:y
a) f points to max of x and y
b) f points to min of x and y
c)error
Answer :a

239. Which of the function operator cannot be over loaded
(a) <=
(b) ?:
(c) =
(d) *

Answer :

240. A static function. say s(),in as file function call can be invoked from

Answer :

All functions. in f.c after the definition of s.

241.Macros and functions do not differ in the following aspects

Answer :

Variable no of arguments.

242.which of the following is correct
A) static enum num{ON,OFF}
B)static const enum num{ON, OFF}
C)const enum num{ON, OFF}
D)None

Answer :

243. Which of the following will print the sum of the values from10 – 100 assuming that post is initialized to 0
A) for(int I=;post ==0;I<=0;I++)
a==a+I
B) for(int I=;I<=0;I++)
a==a+I

Answer :

244. which of the following is not gives an l value a) a b)*(a+I) c)&a[I] d)NoneAnswer :

245.Register variables can hold

a Garbage values

b Arrays

c Double values

d All of the above

Answer :

246.When an array is passed to a function what exactly is passed.

  1. the values of the array
  2. the address of the starting variable in the array.
  3. The addresses of the elements in the array
  4. None

Answer :

247.Compiler recognizes the function as pure virtual function if

A The function if equated to 0.

B the function has no body

C if it is declared with the keyword virtual

D none

Answer :

248. When an array is passed as parameter to a function, which of the following statement is correct

choice:

a) The function can change values in the original array

b) In C parameters are passed by value. The function cannot change the original value in the array

c) It results in compilation error when the function tries to access the elements in the array

d) Results in a run time error when the funtion tries to access the elements in the array

Answer: a

249. The type of the controlling statement of a switch statement cannot be of the type

a) int b) char c) short d)float e) none

Answer : d

250. Macros and function are related in what aspect?

(a)recursion

(b)varying no of arguments

(c)hypochecking

(d)type declaration

Answer : d or a (check)

251.Preprocessor does not do which one of the following

(a) macro

(b) conditional compliclation

(c) in type checking

(d) including load file

Answer : (c)

POINTERS:

1. Find the output

main()

{

char *p;

p=malloc(10);

free(p);

printf("%d",p);

}

Answer :

compilation error

2.output is

main()
{
char *p1="Name";
char *p2;
p2=(char *)malloc(20);
while(*p2++=*p1++);
printf("%s\n",p2);
}

Answer :

3.output

#include<stdio.h>
main()
{
char *p1;
char *p2;
p1=(char *) malloc(25);
p2=(char *) malloc(25);
strcpy(p1,"Ramco");
strcpy(p2,"Systems");
strcat(p1,p2);
printf("%s",p1);
}

Answer :

4. Comment

main()

{

char *c;

int *ip;

c =(char *)malloc(100);

ip=(int *)c;

free(ip);

}

Answer :

The code functions properly releasing all the memory allocated

5. 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]);

}

Answer:

Compiler error: Lvalue required in function main

Explanation:

Array names are pointer constants. So it cannot be modified.

6. 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

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.

7. main()

{

char *p;

printf("%d %d ",sizeof(*p),sizeof(p));

}

Answer:

1 2

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 sizeof(p) gives 2.

8.void main()

{

char far *farther,*farthest;

printf("%d..%d",sizeof(farther),sizeof(farthest));

}

Answer:

4..2

Explanation:

the second pointer is of char type and not a far pointer

9.main()

{

int i, n;

char *x = “girl”;

n = strlen(x);

*x = x[n];

for(i=0; i<n; ++i)

{

printf(“%s\n”,x);

x++;

}

}

Answer:

(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 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.

10.main()

{

char *p;

int *q;

long *r;

p=q=r=0;

p++;

q++;

r++;

printf("%p...%p...%p",p,q,r);

}

Answer:

0001...0002...0004

Explanation:

++ operator when applied to pointers increments address according to their corresponding data-types.

11.# include <stdio.h>

int one_d[]={1,2,3};

main()

{

int *ptr;

ptr=one_d;

ptr+=3;

printf("%d",*ptr);

}

Answer:

garbage value

Explanation:

ptr pointer is pointing to out of the array range of one_d.

12.# 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]();

}

Answer:

bye

Explanation:

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.

13.main()

{

char *p;

p="%d\n";

p++;

p++;

printf(p-2,300);

}

Answer:

300

Explanation:

The pointer points to % since it is incremented twice and again decremented by 2, it points to '%d\n' and 300 is printed.

14. Find the output

int aaa() {printf(“Hi”);}

int bbb(){printf(“hello”);}

iny ccc(){printf(“bye”);}

main()

{

int ( * ptr[3]) ();

ptr[0] = aaa;

ptr[1] = bbb;

ptr[2] =ccc;

ptr[2]();

}

Answer:

bye

Explanation:

int (* ptr[3])() says that ptr is an array of pointers to functions that takes no arguments and returns the type int. By the assignment ptr[0] = aaa; it means that the first function pointer in the array is initialized with the address of the function aaa. Similarly, the other two array elements also get initialized with the addresses of the functions bbb and ccc. Since ptr[2] contains the address of the function ccc, the call to the function ptr[2]() is same as calling ccc(). So it results in printing "bye".

15.main()

{

int a=2,*f1,*f2;

f1=f2=&a;

*f2+=*f2+=a+=2.5;

printf("\n%d %d %d",a,*f1,*f2);

}

Answer:

16 16 16

Explanation:

f1 and f2 both refer to the same memory location a. So changes through f1 and f2 ultimately affects only the value of a.