1.
#include
int main()
{
int a=10;
switch(a)
{
case '1':
printf("ONE\n");
break;
case '2':
printf("TWO\n");
break;
defa1ut:
printf("NONE\n");
}
return 0;
}


2.
The following C program segfaults of IA-64, but works fine on IA-32.

int main()
{
int* p;
p = (int*)malloc(sizeof(int));
*p = 10;
return 0;
}

Why does it happen so?


3.
int main()
{
float f=0.0f;
int i;


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

f = f + 0.1f;


if(f == 1.0f)

printf("f is 1.0 \n");

else
printf("f is NOT 1.0\n");


return 0;

}



4.

#include

int main()
{
int a = 1,2;
printf("a : %d\n",a);
return 0;
}


5.

#include
int main()
{
int i=43;
printf("%d\n",printf("%d",printf("%d",i)));
return 0;
}

6.
Are the following two function prototypes same?

int foobar(void);
int foobar();

The following programs should be of some help in finding the answer: (Compile and run both the programs and see what happens)
Program 1:

#include
void foobar1(void)
{
printf("In foobar1\n");
}

void foobar2()
{
printf("In foobar2\n");
}

int main()
{
char ch = 'a';
foobar1();
foobar2(33, ch);
return 0;
}

Program 2:

#include
void foobar1(void)
{
printf("In foobar1\n");
}

void foobar2()
{
printf("In foobar2\n");
}

int main()
{
char ch = 'a';
foobar1(33, ch);
foobar2();
return 0;
}

7.

What's the output of the following program and why?

#include
int main()
{
float a = 12.5;
printf("%d\n", a);
printf("%d\n", *(int *)&a);
return 0;
}

Comments

  1. for question no 1: it will not give any output since switch condition is not satisfying any condition.
    defa1ut is a valid label so it will not give any error too.

    ReplyDelete
  2. Can u please elaborate the ans of Q 7.

    ReplyDelete
  3. sir, what is the explanation of question no 3rd.

    ReplyDelete
  4. @above when ever we declare a variable with float value say f = 0.1f then it has its value equal to 0.1 upto some precision.try this and you will get the answer:

    float f = 0.1f;

    printf("%.18f",f);

    ReplyDelete

Post a Comment

Popular posts from this blog