C/C / Sample Test,Sample questions

Question:
Comment on the following expression? c = (n) ? a : b; can be rewritten as

1.if (!n)c = b; else c = a

2.if (n <= 0)c = b; else c = a

3. if (n > 0)c = a; else c = b;

4.All of the mentioned

Posted Date:-2022-03-21 07:44:53


Question:
Comment on the output of this C code?

void main()
{
int k = 8;
int m = 7;
int z = k < m ? k = m : m++;
printf("%d", z);
}

1.Run time error

2.7

3.8

4.Depends on compiler

Posted Date:-2022-03-21 07:37:03


Question:
For initialization a = 2, c = 1 the value of a and c after this code will be c = (c) ? a = 0 : 2;

1.a = 0, c = 0;

2.a = 2, c = 2;

3.a = 2, c = 2

4. a = 1, c = 2;

Posted Date:-2022-03-21 07:40:59


Question:
The code snippet below produces

void main()
{
1 < 2 ? return 1 : return 2;
}

1.returns 1

2.returns 2

3.varies

4.Compile time error

Posted Date:-2022-03-21 07:39:13


Question:
The output of the code below is

void main()
{
int k = 8;
int m = 7;
k < m ? k = k + 1 : m = m + 1;
printf("%d", k);
}

1.Compile time error

2.9

3.8

4.Run time error

Posted Date:-2022-03-21 07:40:21


Question:
The output of the code below is

void main()
{
int k = 8;
int m = 7;
k < m ? k++ : m = k;
printf("%d", k);
}

1.7

2.8

3.Compile time error

4.Run time error

Posted Date:-2022-03-21 07:39:46


Question:
Value of c after the following expression (initializations a = 1, b = 2, c = 1): c += (-c) ? a : b;

1.syntax error

2.c = 1

3.c = 2

4.c = 3

Posted Date:-2022-03-21 07:44:00


Question:
What is the output of this C code?

int main()
{
int a = 2;
int b = 0;
int y = (b == 0) ? a :(a > b) ? (b = 1): a;
printf("%d
", y);
}

1.Compile time error

2.1

3.2

4.Undefined behaviour

Posted Date:-2022-03-21 07:35:24


Question:
What is the output of this C code?

int main()
{
int x = 1;
int y = x == 1 ? getchar(): 2;
printf("%d
", y);
}

1.Compile time error

2.Whatever character getchar function returns

3.Ascii value of character getchar function returns

4.2

Posted Date:-2022-03-21 07:34:21


Question:
What is the output of this C code?

int main()
{
int x = 1;
short int i = 2;
float f = 3;
if (sizeof((x == 2) ? f : i) == sizeof(float))
printf("float
");
else if (sizeof((x == 2) ? f : i) == sizeof(short int))
printf("short int
");
}

1.float

2.short int

3.Undefined behaviour

4.Compile time error

Posted Date:-2022-03-21 07:35:00


Question:
What is the output of this C code?

int main()
{
int x = 2, y = 0;
int z = (y++) ? y == 1 && x : 0;
printf("%d
", z);
return 0;
}

1.0

2.1

3.Undefined behavior

4.Compile time error

Posted Date:-2022-03-21 07:33:42


Question:
What is the output of this C code?

int main()
{
int y = 1, x = 0;
int l = (y++, x++) ? y : x;
printf("%d
", l);
}

1.1

2.2

3.Compile time error

4.Undefined behaviour

Posted Date:-2022-03-21 07:35:55


Question:
What is the output of this C code?

void main()
{
int k = 8;
int m = 7;
int z = k < m ? k++ : m++;
printf("%d", z);
}

1.7

2.8

3.Run time error

4.None of the mentioned.

Posted Date:-2022-03-21 07:36:30


Question:
What will be the data type of the expression (a < 50) ? var1 : var2; provided a = int, var1 = double, var2 = float

1.float

2.int

3.double

4.Cannot be determined

Posted Date:-2022-03-21 07:41:57


Question:
Which expression has to be present in the following? exp1 ? exp2 : exp3;

1.exp1

2.exp2

3.exp3

4.All of the mentioned

Posted Date:-2022-03-21 07:42:47


More MCQS

  1. help4info.com
  2. help4info.com
  3. help4info.com
Search
R4R Team
R4Rin Top Tutorials are Core Java,Hibernate ,Spring,Sturts.The content on R4R.in website is done by expert team not only with the help of books but along with the strong professional knowledge in all context like coding,designing, marketing,etc!