github

Made bySaurav Hathi

Test C/C++: Miscellaneous 1

Q1:

What is the output of this C++ program if we give 1 as input?

#include <iostream>

#include <ios>

#include <istream>

#include <limits>

using namespace std;

template <typename CharT>

void ignore_line ( basic_istream<CharT>& in )

{

in.ignore ( numeric_limits<streamsize> :: max(), in.widen ( '\n' ) );

}

int main()

{

cout << "First input: ";

cin.get();

cout << "Clearing cin.\n";

cin.clear();

ignore_line ( cin );

cout << "All done.\n";

return 0;

}

Tags:
Section:
Core Programming
Options:
Q2:

What is the output of this C++ program?

#include <iostream>

using namespace std;

int main( )

{

char line[100];

cin.getline( line, 100, 't' );

cout << line;

return 0;

}

Tags:
Section:
Core Programming
Options:
Q3:

How many objects are used for input and output to a string in C++?

Tags:
Section:
Core Programming
Options:
Q4:

What is the output of this C++ program?

#include <iostream>

using namespace std;

int main ()

{

char first, second;

cout << "Enter a word: ";

first = cin.get();

cin.sync();

second = cin.get();

cout << first << endl;

cout << second << endl;

return 0;

}

Tags:
Section:
Core Programming
Options:
Q5:

What is the output of this C++ program?

#include <iostream>

using namespace std;

int main ()

{

int a = 100;

double b = 3.14;

cout << a<<endl;

cout << b << endl << a * b;

endl (cout);

return 0;

}

Tags:
Section:
Core Programming
Options:
Q6:

What is the output of this C code?

#include <stdio.h>

int main()

{

printf("Hello World! %d \n", x);

return 0;

}

Tags:
Section:
Core Programming
Options:
Q7:

What will happen if the below C program is executed?

#include <stdio.h>

int main()

{

int main = 3;

printf("%d", main);

return 0;

}

Tags:
Section:
Core Programming
Options:
Q8:

In C, the format identifier ā€˜%i’ is also used for _____ data type?

Tags:
Section:
Core Programming
Options:
Q9:

What is the output of this C code?

#include <stdio.h>

int main()

{

float x = 'a';

printf("%f", x);

return 0;

}

Tags:
Section:
Core Programming
Options:
Q10:

What is the output of this C code?

#include <stdio.h>

int main()

{

printf("C programming %s", "Class by\n%s Sanfoundry", "WOW");

return 0;

}

Tags:
Section:
Core Programming
Options:
Q11:

What is the output of this C code?

#include <stdio.h>

#define a 10

int main()

{

const int a = 5;

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

return 0;

}

Tags:
Section:
Core Programming
Options:
Q12:

What is the output of this C code?

#include <stdio.h>

int main()

{

int var = 010;

printf("%d", var);

return 0;

}

Tags:
Section:
Core Programming
Options:
Q13:

What is the output of this C code?

#include <stdio.h>

int main()

{

j = 10;

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

return 0;

}

Tags:
Section:
Core Programming
Options:
Q14:

What is the output of this C code?

#include <stdio.h>

int main()

{

int i = -3;

int k = i % 2;

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

return 0;

}

Tags:
Section:
Core Programming
Options:
Q15:

What is the output of this C code?

#include <stdio.h>

int main()

{

int i = 3;

int l = i / -2;

int k = i % -2;

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

return 0;

}

Tags:
Section:
Core Programming
Options:
Q16:

What will be the output of given C code?

#include <stdio.h>

struct temp

{

int a;

int b;

int c;

};

main()

{

struct temp p[] = {{1, 2, 3}, {4, 5, 6}, {7, 8, 9}};

}

Tags:
Section:
Core Programming
Options:
Q17:

What is the output of this C code?

#include <stdio.h>

struct student

{

char *name;

};

struct student s[2];

int main()

{

s[0].name = "alan";

s[1] = s[0];

printf("%s %s ", s[0].name, s[1].name);

s[1].name = "wang";

printf("%s %s ", s[0].name, s[1].name);

}

Tags:
Section:
Core Programming
Options:
Q18:

What is the output of this C code?

#include <stdio.h>

struct p

{

int x;

char y;

};

int main()

{

struct p p1[] = {1, 92, 3, 94, 5, 96};

struct p *ptr1 = p1;

int x = (sizeof(p1) / 3);

if (x == sizeof(int) + sizeof(char))

printf("%d\n", ptr1->x);

else

printf("false\n");

}

Tags:
Section:
Core Programming
Options:
Q19:

What is the output of this C code?

#include <stdio.h>

struct p

{

int x;

char y;

};

int main()

{

struct p p1[] = {1, 92, 3, 94, 5, 96};

struct p *ptr1 = p1;

int x = (sizeof(p1) / sizeof(ptr1));

if (x == 1)

printf("%d\n", ptr1->x);

else

printf("false\n");

}

Tags:
Section:
Core Programming
Options:
Q20:

What is the output of this C code(size of int and float is 4)?

#include <stdio.h>

union

{

int ival;

float fval;

} u;

int main()

{

printf("%d", sizeof(u));

}

Tags:
Section:
Core Programming
Options: