IEEE-ASET-C/C++ Programmer Hunt
ANSKEY
Note: Ans
marked in ‘*’
No of Questions: 23
Time: 20 min
Instructions:
1 +3 for correct, -1 for each wrong
answer, except Q 8,Q 9
2 Answer in space provided
3 NO CUTTING allowed, USE ALL HEADER FILES
YOU NEED , NO RESTRICTION
Q1. int
z,x=5,y=-10,a=4,b=2;
z = x++ - --y * b / a;
What number will z in the sample code above contain?
(1) 5 (2) 6 (3) 10* (4) 11 (5) 12
Q2. "My salary was increased by 15%!"
Select the statement which will EXACTLY reproduce the line of text above.
(1) printf("\"My
salary was increased by 15/%\!\"\n");
(2) printf("My salary was
increased by 15%!\n")
(3) printf("My salary was
increased by 15'%'!\n");
(4) printf("\"My
salary was increased by 15%%!\"\n");*
(5) printf("\"My
salary was increased by 15'%'!\"\n");
Q3. void *ptr;
myStruct myArray[10];
ptr = myArray;
Which of the following is the correct way to increment the variable "ptr"?
(1) ptr = ptr + sizeof(myStruct); *
(2) ++(int*)ptr;
(3) ptr = ptr + sizeof(myArray);
(4) increment(ptr);
(5) ptr = ptr + sizeof(ptr);
Q4. What is a difference between a
declaration and a definition of a variable?
(1) Both can occur multiple times, but a declaration must occur first.
(2) There is no difference
between them.
(3) A definition occurs once, but
a declaration may occur many times.
(4) A declaration occurs once,
but a definition may occur many times.*
(5) Both can occur multiple
times, but a definition must occur first.
Q5. int testarray[3][2][2]
= {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12};
What value does testarray[2][1][0] in the sample code
above contain?
(1) 8 (2) 9 (3) 10 (4) 11 * (5) are u kiddin
me ??
Q6..int a=10,b;
b=a++ + ++a;
printf("%d,%d,%d,%d",b,a++,a,++a);
what will be the output when following code is executed
(1) 12,10,11,13 (2) 22,10,11,13 (3) 22,11,12,13 (4) 12,11,11,11
(5) 22,13,13,13*
Q7.Can you declare the static data
member in ‘C’ struct?
(1) True (2) False * (3) Maybe,depends
on the declaration method
Q8.Why static member functions
cannot access the ordinary data members?
Answer in space provided.(+6 marks for correct
-2 for wrong)
Static
member functions cannot access the ordinary data member function
because the address of the current object quietly passed
in when any member
function is called, but static member function has no this
pointer
Q9 .Which are the operators
that you cannot overload?
Answer in space provided.(+1 marks for each correct operator -1 for each wrong, max
6)
See the text book
Q10. #define MAX(x,y)
(x)>(y)?(x):(y)
{int i=10;
j=5;
k=0;
k=MAX(i++,++j);
printf(%d %d %d %d,i,j,k);
}
output???
(1) 10 5 0 (2) 11 6 0 (3) 9 5 2 (4) 11 6 3 (5) 10 6 1*
Q 11.Output??
void main()
{
int i=7;
printf("%d",i++*i++);
}
(1) 72 (2) 56 * (3) 8,9 (4)7,8 (5) error
Q 12.Output??
main()
{
char *ptr = "Ramco
Systems";
(*ptr)++;
printf("%s\n",ptr);
ptr++;
printf("%s\n",ptr);
}
write down the
correct output,write error if error is present
Samco Systems
amco Systems
Q13. int i;
i=1;
i=i+2*i++;
printf(“%d”,i);
Output??
(1) 4 * (2) 5 (3) 6
(4) 3 (5) 2
Q14 int i;
i=1;
printf(“%d”, i+2*++i);
Output??
(1) 4 (2) 5 (3) 6
* (4) 3 (5) 2
Q15.
main(){static
int var = 5;
printf("%d
",var--);
if(var)
main();
}
Output??
(1) 56789 (2) 54321 * (3)
4321 (4) 6789 (5) error
Q16. What is the output of the file –heloo.cpp defined as ,
main(){cout<<”Hello its great paper”<<endl;}
(1) Hello its great paper (2) hello its great paper (3) error *
Q17.
#include<malloc.h>
char *f()
{char *s=malloc(8);
strcpy(s,"goodbye");
}main()
{
char
*f();
printf("%c",*f()='A'); }
(1)
A * (2) g (3) goodbye (4) Agoodbye (5) error
Q 18. 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; } }
Output?
(1) 2222223465 * (2)
2222233465 (3) 222223465 (4) error
Q19
main(){
int i=-1,j=-1,k=0,l=2,m;
m=i++&&j++&&k++||l++;
printf("%d %d %d %d %d",i,j,k,l,m); }
Output??
(1) 11131 (2)
00131* (3) 00141 (4) 11121 (5)errors
Q20. main(){
printf("\nab");
printf("\bsi");
printf("\rha");} Output??
(1) hain (2) hai * (3) absiha (4) ab si ha (5) r u serious??
Q21.
#define clrscr()
100
main()
{ clrscr();
printf("%d\n",clrscr());
} Output??
(1)clrscr() (2) 100 * (3) blank screen (4) error,clrscr() is a predefined function (5) some other error
Q 22. main()
{char c=-64;
int i=-32
unsigned int u =-16;
if(c>i)
{printf("pass1,");
if(c<u)
printf("pass2");
else
printf("Fail2");
}
else
printf("Fail1);
if(i<u)
printf("pass2");
else
printf("Fail2")
} output??
(1) Pass1,Pass2 (2) Pass1,Fail2 (3) Fail1,Pass2* (4) Fail1,Fail2 (5) None of these
Q 23. main()
{int i=0;
for(i=0;i<20;i++)
{switch(i)
case 0:i+=5;
case 1:i+=2;
case 5:i+=5;
default i+=4;
break;}
printf("%d,",i);
}
}Output??
(1) 0,5,9,13,17 (2) 5,9,13,17 (3) 12,17,22 (4) 16,21* (5) Syntax error