• Courses
  • Tutorials
  • Jobs
  • Practice
  • Contests

C Operators

Question 21

Output of following C code will be?

C
#include <stdio.h>

int main() {
    int x = 10;
    int y = (x++, x++, x++);
    printf("%d %d\n", x, y);
    return 0;
}
  • 13 12

  • 13 13

  • 10 10

  • Compiler Dependent

Question 22

Output of following C code will be?

C
#include <stdio.h>

int main() {
   int y = 0;
   int x = (y != 0);
   printf("%d", x);
   return 0;
}
  • 0

  • 1

  • A bog negative Number

  • Compiler Error

Question 23

Output of following C code will be?

C
#include <stdio.h>
int main()
{
   int a = 0;
   int b;
   a = (a == (a == 1));
   printf("%d", a);
   return 0;
}
  • 0

  • 1

  • Big negative number

  • -1

Question 24

Output of following C code will be?

C
#include <stdio.h>
#include <stdlib.h>

int top = 0;

char fun1()
{
    char a[] = {'a', 'b', 'c', '(', 'd'};
    return a[top++];
}

int main()
{
    char b[10];
    char ch2;
    int i = 0;
    
    while ((ch2 = fun1()) != '(')
    {
        b[i++] = ch2;
    }
    
    b[i] = '\0'; // Add null-terminating character to mark the end of the string
    
    printf("%s", b);
    
    return 0;
}
  • abc(

  • abc

  • 3 special characters with ASCII value 1

  • Empty String

Question 25

In the context of modulo operation (i.e. remainder on division) for floating point (say 2.1 and 1.1), pick the best statement.
  • For floating point, modulo operation isn\'t defined and that\'s why modulo can\'t be found.
  • (2.1 % 1.1) is the result of modulo operation.
  • fmod(2.1,1.1) is the result of module operation.
  • ((int)2.1) % ((int)1.1) is the result of modulo operation.

Question 26

For a given integer, which of the following operators can be used to “set” and “reset” a particular bit respectively?
  • | and &
  • && and ||
  • & and |
  • || and &&

Question 27

Suppose a, b, c and d are int variables. For ternary operator in C ( ? : ), pick the best statement.
  • a>b ? : ; is valid statement i.e. 2nd and 3rd operands can be empty and they are implicitly replaced with non-zero value at run-time.
  • a>b ? c=10 : d=10; is valid statement. Based on the value of a and b, either c or d gets assigned the value of 10.
  • a>b ? (c=10,d=20) : (c=20,d=10); is valid statement. Based on the value of a and b, either c=10,d=20 gets executed or c=20,d=10 gets executed.
  • All of the above are valid statements for ternary operator.

Question 28

The below program would give compile error because comma has been used after foo(). Instead, semi-colon should be used i.e. the way it has been used after bar(). That\'s why if we use semi-colon after foo(), the program would compile and run successfully while printing "GeeksQuiz" C
#include \"stdio.h\"

void foo(void)
{
 printf(\"Geeks\");
}
void bar(void)
{
 printf(\"Quiz\");
}

int main()
{
 foo(), bar();
 return 0;
}
  • TRUE
  • FALSE

Question 29

What does the following program do when the input is unsigned 16-bit integer?
#include 
main( )
{
unsigned int num;
int i;
scanf (“%u”, &num);
for ( i = 0; i<16; i++)
{
printf (“%d”, (num << i & 1 << 15 ) ? 1:0);
}
}
  • It prints all even bits from num
  • It prints all odd bits from num
  • It prints binary equivalent of num
  • None of the above

Question 30

Which of the following operators cannot be overloaded in C/C++ ?
  • Bitwise right shift assignment
  • Address of
  • Indirection
  • Structure reference

There are 41 questions to complete.

Last Updated :
Take a part in the ongoing discussion