Color Scheme : DEFAULT  
Welcome Guest Login or Signup
   


Groups >> Source For Dream JOB....... >> Forum >> C mcq's(technical )

Viewing 1 - 4 out of 4 posts




POSTED BY: Tejahys on Nov 8, 2007
C mcq's(technical )

void main()
{
 int  const * p=5;
 printf("%d",++(*p));
}


Answer:
Compiler error: Cannot modify a constant value.


Explanation:
p is a pointer to a "constant integer". But we tried to change the value of the "constant integer".
main()
{
 char s[ ]="man";
 int i;
 for(i=0;s[ i ];i++)
 printf("n%c%c%c%c",s[ i ],*(s+i),*(i+s),i[s]);
}


Answer:
mmmm
aaaa
nnnn


Explanation:
s[i], *(i+s), *(s+i), i[s] are all different ways of expressing the same idea. Generally array name is the base address for that array. Here s is the base address. i is the index number/displacement from the base address. So, indirecting it with * is same as s[i]. i[s] may be surprising. But in the case of C it is same as s[i].
main()
{
 float me = 1.1;
 double you = 1.1;
 if(me==you)
printf("I love U");
else
  printf("I hate U");
}


Answer:
I hate U


Explanation:
For floating point numbers (float, double, long double) the values cannot be predicted exactly. Depending on the number of bytes, the precession with of the value represented varies. Float takes 4 bytes and long double takes 10 bytes. So float stores 0.9 with less precision than long double.


Rule of Thumb:
Never compare or at-least be cautious when using floating point numbers with relational operators (== , ,





--------------------------------------------------------------
Dont kill the Dreams..execute ittt
Back To Top




POSTED BY: Tejahys on Nov 8, 2007
C mcq's..part-2

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.
main()
{
 int i=3;
 switch(i)
  {
     default:printf("zero");
     case 1: printf("one");
     break;
    case 2:printf("two");
    break;
   case 3: printf("three");
    break;
   } 
}


Answer :
three


Explanation :
The default case can be placed anywhere inside the loop. It is executed only when all other cases doesn't match.
main()
{
   printf("%x",-1





--------------------------------------------------------------
Dont kill the Dreams..execute ittt
Back To Top




POSTED BY: Tejahys on Nov 8, 2007
C mcq's part-3

#include‹stdio.h›
main()
{
int a[2][2][2] = { {10,2,3,4}, {5,6,7,8}  };
int *p,*q;
p=&a[2][2][2];
*q=***a;
printf("%d----%d",*p,*q);
}


Answer:
SomeGarbageValue---1


Explanation:
p=&a[2][2][2] you declare only two 2D arrays, but you are trying to access the third 2D(which you are not declared) it will print garbage values. *q=***a starting address of a is assigned integer pointer. Now q is pointing to starting address of a. If you print *q, it will print first element of 3D array.



#include‹stdio.h›
main()
{
struct xx
{
      int x=3;
      char name[]="hello";
 };
struct xx *s;
printf("%d",s-x);
printf("%s",s-name);
}


Answer:
Compiler Error


Explanation:
You should not initialize variables in declaration
#include‹stdio.h›
main()
{
struct xx
{
int x;
struct yy
{
char s;
 struct xx *p;
};
struct yy *q;
};
}
Answer:
Compiler Error


Explanation:
The structure yy is nested within structure xx. Hence, the elements are of yy are to be accessed through the instance of structure xx, which needs an instance of yy to be known. If the instance is created after defining the structure the compiler will not know about the instance relative to xx. Hence for nested structure yy you have to declare member.
main()
{
printf("nab");
printf("bsi");
printf("rha");
}


Answer:
hai


Explanation:
n - newline
b - backspace
r - linefeed
main()
{
int i=5;
printf("%d%d%d%d%d%d",i++,i--,++i,--i,i);
}


Answer:
45545


Explanation:
The arguments in a function call are pushed into the stack from left to right. The evaluation is by popping out from the stack. and the evaluation is from right to left, hence the result.
#define square(x) x*x
main()
{
int i;
i = 64/square(4);
printf("%d",i);
}


Answer:
64
Explanation:
the macro call square(4) will substituted by 4*4 so the expression becomes i = 64/4*4 . Since / and * has equal priority the expression will be evaluated as (64/4)*4 i.e. 16*4 = 64





--------------------------------------------------------------
Dont kill the Dreams..execute ittt
Back To Top




POSTED BY: Tejahys on Nov 8, 2007
C mcq's technical part-4..

main()
{
char *p="hai friends",*p1;
p1=p;
while(*p!='





--------------------------------------------------------------
Dont kill the Dreams..execute ittt
Back To Top
Nov 19, 2026


*** NkuT.Com ***