Operators
- What will be the final values of p and q in the following C statement? (Initial values: p = 2, q = 1)
q = (q) ? p = 0 : 2;
-
View Hint View Answer Discuss in Forum
NA
Correct Option: D
p = 0, q = 0;
- What will be the output of the following C code?
#include <stdio.h>
void main()
{
int n1 = 15;
int n2 = 16;
n1 < n2 ? n1 = n1 + 1 : n2 = n2 + 1;
printf("%d", n1);
}
-
View Hint View Answer Discuss in Forum
NA
Correct Option: C
Compilation Error
main.c: In function ‘main’:
main.c:6:36: error: lvalue required as left operand of assignment
n1 < n2 ? n1 = n1 + 1 : n2 = n2 + 1;
- What will be the output of the following C code?
#include <stdio.h>
void main()
{
int num1 = 10;
int num2 = 11;
num1 < num2 ? num1++ : num2 = num1;
printf("%d", num1);
}
-
View Hint View Answer Discuss in Forum
NA
Correct Option: D
Compilation Error
main.c: In function ‘main’:
main.c:6:37: error: lvalue required as left operand of assignment
num1 < num2 ? num1++ : num2 = num1;
- What will be the output of the following C code?
#include <stdio.h>
void main()
{
2 < 3 ? return 2 : return 3;
}
-
View Hint View Answer Discuss in Forum
NA
Correct Option: D
Compilation Error
main.c: In function ‘main’:
main.c:4:17: error: expected expression before ‘return’
2 < 3 ? return 2 : return 3;
- What will be the output of the following C code?
#include <stdio.h>
void main()
{
int num1 = 12;
int num2 = 10;
int num3 = num1 < num2 ? num1 = num2 : num2++;
printf("%d", num3);
}
-
View Hint View Answer Discuss in Forum
NA
Correct Option: D
10