C technical question


C basic interview questions and answers for freshers

 

1.Find out put of the program.

#include<stdio.h>

#include<math.h>

int main()

{

    float a=5.375;

    char *p;

    int i;

    p = (char*)&a;

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

        printf("%02x\n", (unsigned char)p[i]);

    return 0;

}

Answer= 00 00 AC 40

2.Find out output of the program.

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

3.Find Output Of the c program.

main()
{
static int var = 5;
printf("%d ",var--);
if(var)
main();
}

Answer:
5 4 3 2 1

4.Find out output of enum program enum.

enum colors {BLACK,BLUE,GREEN}
main()
{

printf("%d..%d..%d",BLACK,BLUE,GREEN);

return(1);
}

Answer:
0..1..2

5.Find Out put of the program macro

#define f(g,g2) g##g2
main()
{
int var12=100;
printf("%d",f(var,12));
}


Answer:
100

 

 

6.find out put of the program.

#include<stdio.h>

int main()

{

    float a=0.7;

    if(a < 0.7)

        printf("C\n");

    else

        printf("C++\n");

    return 0;

}

Answer= C

7.find out put of the program.

#include<stdio.h>

 

int main()

{

    int a[5] = {5, 1, 15, 20, 25};

    int i, j, m;

    i = ++a[1];

    j = a[1]++;

    m = a[i++];

    printf("%d, %d, %d", i, j, m);

    return 0;

}

Answer= 3, 2, 15

8.Find out put of the program.

#include<stdio.h>

 

int main()

{

    static int a[2][2] = {1, 2, 3, 4};

    int i, j;

    static int *p[] = {(int*)a, (int*)a+1, (int*)a+2};

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

    {

        for(j=0; j<2; j++)

        {

            printf("%d, %d, %d, %d\n", *(*(p+i)+j), *(*(j+p)+i),

                                    *(*(i+p)+j), *(*(p+j)+i));

        }

    }

    return 0;

}

Answer= 1, 1, 1, 1

2, 2, 2, 2

2, 2, 2, 2

3, 3, 3, 3

9.find   out put of progtam.

#include<stdio.h>

void fun(int **p);

 

int main()

{

    int a[3][4] = {1, 2, 3, 4, 4, 3, 2, 8, 7, 8, 9, 0};

    int *ptr;

    ptr = &a[0][0];

    fun(&ptr);

    return 0;

}

void fun(int **p)

{

    printf("%d\n", **p);

}

Answer=1

10..Find out put of the program.

#include<stdio.h>

 

int main()

{

    const char *s = "";

    char str[] = "Hello";

    s = str;

    while(*s)

        printf("%c", *s++);

 

    return 0;

}

Answer=Hello

11..Find out put of the program.

#include<stdio.h>

int get();

 

int main()

{

    const int x = get();

    printf("%d", x);

    return 0;

}

int get()

{

    return 20;

}

Answer=20

 

 

 

12..Find out put

#include<stdio.h>

#include<stdlib.h>

 

int main()

{

    union test

    {

        int i;

        float f;

        char c;

    };

    union test *t;

    t = (union test *)malloc(sizeof(union test));

    t->f = 10.10f;

    printf("%f", t->f);

    return 0;

}

Answer=10.100000

13..Find out put

#include<stdio.h>

#include<stdlib.h>

 

int main()

{

    int *p;

    p = (int *)malloc(256 * 256);

    if(p == NULL)

        printf("Allocation failed");

    return 0;

}

Answer=Allocation failed

 

3 comments:

  1. Rajendra lamror is jinda bar jinda bar....................

    ReplyDelete