github

Made bySaurav Hathi

Test C/C++: Input and Output 2

Q1:

What is the output of this C code?

#include <stdio.h>

int main()

{

void *p;

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

p = &a[3];

int *ptr = &a[2];

int n = (int*)p - ptr;

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

}

Tags:
Section:
Core Programming
Options:
Q2:

What is the output of this C code?

#include <stdio.h>

int main()

{

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

int *p = &a[1];

int *ptr = &a[2];

ptr = ptr * 1;

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

}

Tags:
Section:
Core Programming
Options:
Q3:

What is the output of this C code?

#include <stdio.h>

int main()

{

int k = 5;

int *p = &k;

int **m  = &p;

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

}

Tags:
Section:
Core Programming
Options:
Q4:

What is the output of this C code?

#include <stdio.h>

int main()

{

int k = 5;

int *p = &k;

int **m  = &p;

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

}

Tags:
Section:
Core Programming
Options:
Q5:

What is the output of this C code?

#include <stdio.h>

int main()

{

int k = 5;

int *p = &k;

int **m  = &p;

**m = 6;

printf("%d\n", k);

}

Tags:
Section:
Core Programming
Options:
Q6:

Which of the following statements is true if we execute this C code? 

#include <stdio.h>

int main()

{

int a = 1, b = 2, c = 3;

int *ptr1 = &a, *ptr2 = &b, *ptr3 = &c;

int **sptr = &ptr1; //-Ref

*sptr = ptr2;

}

Tags:
Section:
Core Programming
Options:
Q7:

What is the output of this C code?

#include <stdio.h>

int main()

{

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

int *p = a;

printf("%p %p", p, a);

}

Tags:
Section:
Core Programming
Options:
Q8:

What is the output of this C code?

#include <stdio.h>

int main()

{

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

int *p = a;

int **r = &p;

printf("%p %p", *r, a);

}

Tags:
Section:
Core Programming
Options:
Q9:

What is the output of this C code?

#include <stdio.h>

int main()

{

int one = 1, two = 2;

#ifdef next

one = 2;

two = 1;

#endif

printf("%d, %d", one, two);

}

Tags:
Section:
Core Programming
Options:
Q10:

What is the output of this C code?

#include <stdio.h>

#define fun(m, n) m ## n

int main()

{

printf("%s\n", fun(k, l));

}

Tags:
Section:
Core Programming
Options:
Q11:

What is the output of this C code?

#include <stdio.h>

#define fun(x, y) x / y + x

int main()

{

int i = -6, j = 3;

printf("%d\n",fun(i + j, 3));

return 0;

}

Tags:
Section:
Core Programming
Options:
Q12:

What is the output of this C code?

#include <stdio.h>

void fun();

int main()

{

#define max 10

fun();

return 0;

}

void fun()

{

printf("%d\n", max * 10);

}

Tags:
Section:
Core Programming
Options:
Q13:

What is the output of this C code?

#include <stdio.h>

#define SYSTEM 20

int main()

{

int a = 20;

#if SYSTEM == a

printf("HELLO ");

#endif

#if SYSTEM == 20

printf("WORLD\n");

#endif

}

Tags:
Section:
Core Programming
Options:
Q14:

What is the output of this C code?

#include <stdio.h>

#define COLD

int main()

{

#ifdef COLD

printf("COLD\t");

#undef COLD

#endif

#ifdef COLD

printf("HOT\t");

#endif

}

Tags:
Section:
Core Programming
Options:
Q15:

What is the output of this C code?

#include <stdio.h>

struct student

{

int no;

char name[20];

}

int main()

{

struct student s;

s.no = 8;

printf("hello");

}

Tags:
Section:
Core Programming
Options:
Q16:

What is the output of this C code?

#include <stdio.h>

struct

{

int k;

char c;

};

int main()

{

struct p;

p.k = 10;

printf("%d\n", p.k);

}

Tags:
Section:
Core Programming
Options:
Q17:

What is the output of this C code?

#include <stdio.h>

struct p

{

int k;

char c;

float f;

};

int p = 10;

int main()

{

struct p x = {1, 97};

printf("%f %d\n", x.f, p);

}

Tags:
Section:
Core Programming
Options:
Q18:

What is the output of this C++ code?

#include <iostream>
using namespace std;
struct p

{

char c;

int k;

float f;

};

int main()

{

struct p x = {c : 97, k : 1};

cout<<x.f;

}

Tags:
Section:
Core Programming
Options:
Q19:

What is the output of this C code?

#include <stdio.h>

struct student

{

char *name;

};

struct student s;

struct student foo(void)

{

s.name = "harry";

printf("%s ", s.name);

return s;

}

int main()

{

struct student m = foo();

printf("%s ", m.name);

m.name = "alan";

printf("%s ", s.name);

}

Tags:
Section:
Core Programming
Options:
Q20:

What’s the output of the following C code?

#include <stdio.h>

struct temp

{

int a;

} s;

void foo(struct temp s)

{

s.a = 10;

printf("%d ", s.a);

}

main()

{

foo(s);

printf("%d ", s.a);

}

Tags:
Section:
Core Programming
Options: