C Operators

    Last Updated :
    Discuss
    Comments

    Question 1

    The following three 'C' language statements is equivalent to which single statement? y=y+1; z=x+y; x=x+1

    • z = x + y + 2;

    • z = (x++) + (++y);

    • z = (x++) + (y++);

    • z = (x++) + (++y) + 1;

    Question 2

    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 3

    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 4

    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 5

    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 6

    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 7

    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 8

    What does the following program do when the input is unsigned 16-bit integer?

    C
    #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 9

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

    Question 10

    Write the output of the following C program

    C
    #include <stdio.h>
    
      int main (void)
      {
      int shifty;
      shifty = 0570;
      shifty = shifty >>4;
      shifty = shifty <<6;
      printf("the value of shifty is %o",shifty);
      }
    
    • the value of shifty is 15c0

    • the value of shifty is 4300

    • the value of shifty is 5700

    • the value of shifty is 2700

    Tags:

    There are 45 questions to complete.

    Take a part in the ongoing discussion