Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
17 views

Coding Contest With Answers

The document contains questions about C programming concepts like data types, operators, functions, arrays, pointers and structures. Multiple choice options are given as possible answers for each question.

Uploaded by

pushpa
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
17 views

Coding Contest With Answers

The document contains questions about C programming concepts like data types, operators, functions, arrays, pointers and structures. Multiple choice options are given as possible answers for each question.

Uploaded by

pushpa
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 21

1. What will be the output of the program?

#include<stdio.h>
int main()
{
float a = 0.7;
if(0.7 > a)
printf("Hi\n");
else
printf("Hello\n");
return 0;
}
A. Hi

B. Hello

C. None of these

D. error

2. Point out the error in the following code?


typedef struct
{
int data;
NODEPTR link;
}*NODEPTR;

A. Error: in *NODEPTR
B. Error: typedef cannot be used until it is defined
C. No error
D. None of above

3. What will be the output of following program?

#include < stdio.h >


int main()
{
char *str="IncludeHelp";
printf("%c\n",*&*str);
return 0;
}

A. ERROR
B. IncludeHelp
C. NO OUTPUT
D. I

4. Which of the following statements correctly assigns 12 to month using pointer variable pdt?
#include<stdio.h>
struct date
{
int day;
int month;
int year;
};
int main()
{
struct date d;
struct date *pdt;
pdt = &d;
return 0;
}
A. pdt.month = 12
B. &pdt.month = 12
C. d.month = 12
D. pdt->month = 12

5. Point out the error in the program?

#include<stdio.h>
int main()
{
struct emp
{
char n[20];
int age;
};
struct emp e1 = {"Dravid", 23};
struct emp e2 = e1;
if(e1 == e2)
printf("The structure are equal");
return 0;
}
A. Prints: The structure are equal
B. Error
C. No output
D. None of above

6. Output?

main()

int a=10,*j;

void *k;

j=k=&a;

j++;

k++;

printf("\n %u %u ",j,k);

A. 10 11
B. ERROR: illegal type casting
C. ERROR: void pointer cannot be incremented
D. NO OUTPUT

7. What will be the output of the program?


#include<stdio.h>
int main()
{
void fun(char*);
char a[100];
a[0] = 'A'; a[1] = 'B';
a[2] = 'C'; a[3] = 'D';
fun(&a[0]);
return 0;
}
void fun(char *a)
{
a++;
printf("%c", *a);
a++;
printf("%c", *a);
}

A. AB
B. BC
C. CD
D. No output

8.main()
{
char*p;
int*q;
long*r;
p=q=r=0;
p++;
q++;
r++;
printf("%p...%p...%p",p,q,r);
}

A.0001...0002...0004 bbb

B.0002...0003...0004

C.0000...0001...0004

D.0001...0004...0002

9.Predict the output or error(s) for the following:


struct aaa{
struct aaa *prev;
int i;
struct aaa *next;
};
main()
{
struct aaa abc,def,ghi,jkl;
int x=100;
abc.i=0;abc.prev=&jkl;
abc.next=&def;
def.i=1;def.prev=&abc;def.next=&ghi;
ghi.i=2;ghi.prev=&def;
ghi.next=&jkl;
jkl.i=3;jkl.prev=&ghi;jkl.next=&abc;
x=abc.next->next->prev->next->i;
printf("%d",x);
}

A.4

B.3

C.2

D.1

10.main()
{
inti=_l_abc(10);

printf("%d\n",--i);
}
int_l_abc(inti)
{
return(i++);
}

A.10

B.9

C.8

D.11

11. In C, if you pass an array as an argument to a function, what actually gets passed?
A.Value of elements in array
B.First element of the array
C.Base address of the array
D.Address of the last element of array

12. . In the following program add a statement in the function fun() such that address of a gets
stored in j?

#include<stdio.h>
int main()
{
int *j;
void fun(int**);
fun(&j);
return 0;
}
void fun(int **k)
{
int a=10;
/* Add a statement here */
}

A. **k=a;

B. k=&a;

C.*k=&a;

D. &k=*a

12. What will be the output of the program?


#include<stdio.h>
int main()
{
typedef float f;
static f *fptr;
float fval = 90;
fptr = &fval;
printf("%f\n", *fptr);
return 0;
}
A. 9
B. 0
C. 90.000000
D. 90

13. What will be the output of the program ?


#include<stdio.h>
int main()
{
union var
{
int a, b;
};
union var v;
v.a=10;
v.b=20;
printf("%d\n", v.a);
return 0;
}
A. 10
B. 20
C. 30
D. 0

14. Determine the output

int add(int a=10,int b)

return(a+b)

void main()

cout<<add(2,4);

A.14
B.6

C.garbage value

D.error

15. The size of a structure can be determined by


a. size of variable name
b. size of (struct tag)

A.Only a
B.Only b
C.Both a and b
D.None of these option

16. One that can be modified by the class even when the object of the class or the member
function doing the modification is const it is known as______________

A.member function
B.mutable member
C.constant member
D.none of these

17.classSample
{
public:
int*ptr;
Sample(inti)
{
ptr=newint(i);
}
~Sample()
{
deleteptr;
}
voidPrintVal()
{
cout<<"Thevalueis"<<*ptr;
}
};
voidSomeFunc(Samplex)
{
cout<<"Say I am in someFunc "<<endl;
}
intmain()
{
Samples1=10;
SomeFunc(s1);
s1.PrintVal();
}

A. Say I am in someFunc Null pointer assignment

B. Say I am in someFunc

C. Say I am in someFunc The value is 0

D. Say I am in someFunc The value is NULL

18. Find the output of the following program


classbase
{
public:
intbval;
base(){ bval=0;}
};

class deri:public base


{
public:
intdval;
deri(){ dval=1;}
};
void SomeFunc(base *arr,int size)
{
for(int i=0; i
cout<bval;
cout<<endl;
}

int main()
{
base BaseArr[5];
SomeFunc(BaseArr,5);
deriDeriArr[5];
SomeFunc(DeriArr,5);
}
A.00000,11111

B.00000,00000

C.00000,10101

D.00000,01010

19.Find the output:

main()

inti=5;

printf("%d%d%d%d%d%d",i++,i--,++i,--i,i);

A.45545

B.55544

C.55432

D.65655

20. Find the output:


main()
{
char* str = "hello";
char* ptr = str;
charleast = 127;
while(*ptr++)
least = ((*ptr)<(least))?(*ptr):(least);
printf("%d", least);
}

A. 127

B.0
C.infinite loop

D.runtime eroor

21. What is the output of the following program?


main(){
void swap();
int x = 45, y = 15;
swap(&x,&y);
cout<< “x=”<<x<< “y="”<<y;<br">}
void swap(int *a, int *b){
*a^=*b, *b^=*a, *a^ = *b;

A. x = 15, y =45
B. x =15, y =15
C. x =45 ,y =15
D. x =45 y = 45

22.QUESTION - The null character will take space of

A.0 byte
B.2 byte
C.1 byte
D.8 byte

23. voidmain(){
intres;
res= 56>76 ? return0:return1;
printf("%d",res);

A. 0

B.1

C.compiler error

D.run time error


24. main()

inti=2;

switch(i)

default:printf("zero");

case1: printf("one");

break;

case2:printf("two");

case3: printf("three");

break;

A.two

B.two three

C. zero

D. error

25. What will be the output of the program in 16-bit platform?


#include<stdio.h>
int main()
{
printf("%d, %d, %d", sizeof(3.0f), sizeof('3'), sizeof(3.0));
return 0;
}
A. 8, 1, 4
B. 4, 2, 8
C. 4, 2, 4
D. 10, 3, 4

26. What will be the output of the program?


#include<stdio.h>
int reverse(int);
int main()
{
int no=5;
reverse(no);
return 0;
}i
nt reverse(int no)
{
if(no == 0)
return 0;
else
printf("%d,", no);
reverse (no--);
}
A. Print 5, 4, 3, 2, 1
B. Error
C. Print 5, 4, 3, 2, 1, 0
D. Infinite loop
]

27. . What would be the equivalent pointer expression for referring the array element a[i][j][k][l]

A. &(&(&(&(a+i)+j)+k)+l)

B. *(*(*(*(a+i)+j)+k)+l)

C. (((a+i)+j)+k+l)

D. ((a+i)+j+k+l)

28. . Which three are valid declarations of a char?

1. char c1 = 064770;
2. char c2 = 'face';
3. char c3 = 0xbeef;
4. char c4 = \u0022;
5. char c5 = '\iface';
6. char c6 = '\uface';

A.1, 2, 4

B.1, 3, 6

C.3, 5

D.5 only

29.

void main()

int d=5;

printf("%f",d);

A. 5

B. 5.0

C. compiler error

D. no output

30. void main()

float j;

j=1000*1000;

printf("%f",j);

A. 1000000

B. Overflow
C. Error

D. None

31. a[i] is equal to


A. &a[i]
B. *(a+a)
C. i[a]

32.Is it valid to free a NULL pointer?

int main(void)
{
free(NULL);
return 0;
}
A. Yes
B. No
C. Implementation-dependant
D. Error

33. Given the following source line:

printf("Eh???/n");

What does the output look like?


A. Eh???/n
B. Eh??<newline>
C. Eh?<newline>
D.Eh???

34. main()
{
char string[]="Hello World";
display(string);
}
void display(char *string)
{
printf("%s",string);
}

A.Hello World
B. compiler error

C. runtime error

D. syntax error

35. main()
{
char s[]={'a','b','c','\n','c','\0'};
char *p,*str,*str1;
p=&s[3];
str=p;
str1=s;
printf("%d",++*p + ++*str1-32);
}

A. 47

B. 55

C. 67

D. 77

36. main()
{
int i=400,j=300;
printf("%d..%d");
}

A. No output

B. 400..300

C. Compiler error

D. Syntax error

37. main()
{
int i;
printf("%d",scanf("%d",&i)); // value 10 is given as input here
}
A. 1

B. 10

C. no output

D. error

38. main()
{
int i=0;
for(;i++;printf("%d",i)) ;
printf("%d",i);
}

A. 0

B. 1

C. no output

D. infinite loop

39. main()
{
int *j;
{
int i=10;
j=&i;
}
printf("%d",*j);
}

A. compiler error

B. syntax error

C. 10

D. run time error

40. aaa() {
printf("hi");
}
bbb(){
printf("hello");
}
ccc(){
printf("bye");
}
main()
{
int (*ptr[3])();
ptr[0]=aaa;
ptr[1]=bbb;
ptr[2]=ccc;
ptr[2]();
}

A. error

B. no output

C. bye

D. hello

41. main()
{
int i;
i = abc();
printf("%d",i);
}
abc()
{
_AX = 1000;
}

A. _AX undeclered

B. 1000

C. error

D. no output

42. main(){
int a= 0;
int b = 20;
char x =1;
char y =10;
if(a,b,x,y)
printf("hello");
}

A.no output

B. error

C. hello

D. not compile

43. main()
{
char *p;
p="%d\n";
p++;
p++;
printf(p-2,300);
}

A. 300

B. warning

C. compiled successfully but no output

D. not compiled

44. main()
{
int a[10];
printf("%d",*a+1-*a+3);
}

A. Null pointer exception

B. 4

C. compile time error


D. none of these

45. #define prod(a,b) a*b


main()
{
int x=3,y=4;
printf("%d",prod(x+2,y-1));
}

A. 10

B. error

C. 12

D. 11

46. void main()


{
char far *farther,*farthest;

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

}
A. 4,2

B. 2,2

C. 2,1

D. 1,1

47. void main()


{
int i=5;
printf("%d",i++ + ++i);
}
A. depends on the compiler

B. 12

C. 11

D. error

48. The library function used to find the last occurrence of a character in a string is
A.strnstr()
B.laststr()
C.strrchr()
D.strstr()

49. #define square(x) x*x

main()

inti;

i = 64/square(4);

printf("%d",i);

A. 16

B. 4

C. 64

D. none of these

50.
main()
{
int i=5,j=10;
i=i&=j&&10;
printf("%d %d",i,j);
}

A. 0 0

B. 0 10

C.error

D.1 10

You might also like