C++/ Java Interview Questions - Crompton

1. What is the output of the following program?

main()
{
const int x=get();
cout<}
get()
{
return(20);
}

(a) 20 (b) garbage value (c) Error (d) 0

2. How to call a function whose prototype is given as void f1(int **x)?

(a) int **a; (b) int a; (c) int *a; (d) int a=5;

3. Find the error if any in the following code?

main()
{
int i=1;
for(;
{
Cout<if(i>10)
break;}}

(a) The condition in the for loop is a must
(b) The two semicolons should be dropped
(c) The for loop should be replaced by awhile loop
(d) No error

4. Find the error in the code if any?

int main(void)
{
char strA[10]="compile",strB[10];
my_strcpy(strB,strA);
puts(strB);
}
char * my_strcpy(char *destination,char *source)
{
char *p=destination;
while(*source!='')
{
*p++=*source++;
}
*p='';
return destination;
}

(a) Compilation will give a warning and proceed to execute
(b) The compilation error will occur char *(char *,char *)
(c) It will execute and print compile on screen
(d) None of the above

5. What is the output of the following program?

#include
main()
{
char str[5]="fast";
static char *ptr_to_array = str;
cout<}

(a) Warning will be displayed with the output fast
(b) "fast" will be displayed
(c) Compilation error
(d) none of the above

6. What is the output of the following program?

main()
{
int num,*p;
num=5;
p=#
cout<<*p;
}

(a) 6 (b) 5 (c) Garbage value (d) compilation error

7. What is the output of the following program?
main()
{
int a[3]={2,3,4};
char *p;
p=a;
p=(char *)((int *)p+1);
cout<}
(a) 2 (b) 0 (c) Garbage value (d) 3

8. What is the output of the following program?

main()
{
int i=10;
fn(i);
cout<}
fn(int i)
{
return ++i;
}

(a) 10 (b) 11 (c) 12 (d) Compilation error
Post your comment