Basics Of C Language: Trivia Quiz!

Approved & Edited by ProProfs Editorial Team
The editorial team at ProProfs Quizzes consists of a select group of subject experts, trivia writers, and quiz masters who have authored over 10,000 quizzes taken by more than 100 million users. This team includes our in-house seasoned quiz moderators and subject matter experts. Our editorial experts, spread across the world, are rigorously trained using our comprehensive guidelines to ensure that you receive the highest quality quizzes.
Learn about Our Editorial Process
| By 500060884
5
500060884
Community Contributor
Quizzes Created: 2 | Total Attempts: 439
Questions: 15 | Attempts: 223

SettingsSettingsSettings
Basics Of C Language: Trivia Quiz! - Quiz

.


Questions and Answers
  • 1. 

    Which of the following is not a valid variable name declaration in the C programming language?

    • A.

      Int _a3

    • B.

      Int a_3

    • C.

      Int 3_a

    • D.

      Int _3a

    Correct Answer
    C. Int 3_a
    Explanation
    In the C programming language, variable names cannot start with a number. They must start with either a letter or an underscore. Therefore, the declaration "int 3_a" is not valid because it starts with a number.

    Rate this question:

  • 2. 

    What will happen if the below program is executed?    #include    int main()    {        int main = 3;        printf("%d", main);        return 0;    }

    • A.

      It will cause a compile-time error.

    • B.

      It will cause a run-time error.

    • C.

      It will run without any error and prints 3.

    • D.

      No output and program will terminate abnormally.

    Correct Answer
    C. It will run without any error and prints 3.
    Explanation
    In a function a variable can take the same name as that of the function

    Rate this question:

  • 3. 

    What is the output of the following C code?    #include    int main()    {       signed char chr;       chr = 128;       printf("%d\n", chr);       return 0;    }

    • A.

      128

    • B.

      -128

    • C.

      Depends on the compiler

    • D.

      Compile time error as char can't be assigned an int value

    Correct Answer
    B. -128
    Explanation
    When we exceed the maximum limit of char, it starts taking values from the beginning i.e. -128.

    Rate this question:

  • 4. 

    What is the output of the following C code?    #include    int main()    {       int i;       if(i=0,2,3)        printf("Hello ");       else        printf("World ");            printf("%d",i);       return 0;    }

    • A.

      World 3

    • B.

      World 0

    • C.

      Hello 0

    • D.

      Hello 3

    Correct Answer
    C. Hello 0
    Explanation
    The code first initializes the variable i without assigning any value to it. Then, it checks the condition (i=0,2,3). In this condition, the comma operator is used, which evaluates each expression separated by commas and returns the value of the last expression. In this case, the value of the condition is 3. Since the condition is true, the code executes the printf("Hello ") statement. After that, it prints the value of i, which is 0. Therefore, the output is "Hello 0".

    Rate this question:

  • 5. 

    What is the output of the following C code?    #include <stdio.h>    int main()    {       int i=0,j=0;       while(i<5,j<10)       {        i++;            j++;       }     printf("%d %d",i,j);     return 0;    }

    • A.

      5 5

    • B.

      10 10

    • C.

      10 5

    • D.

      5 10

    Correct Answer
    B. 10 10
    Explanation
    Here, ‘,’ operator in while() will act as LOGICAL OR operator i.e. (i

    Rate this question:

  • 6. 

    What will be the output of this C code?    #include <stdio.h>    int main()    {        float f1 = 0.1;        if (f1 == 0.1)            printf("equal\n");        else            printf("not equal\n");      return 0;    }

    • A.

      Equal

    • B.

      Not equal

    • C.

      Output depends upon compiler

    • D.

      Compile-time error

    Correct Answer
    B. Not equal
    Explanation
    Here, 0.1 is taken as double (by default) by the compiler. So. a float value is not equal to a double value.

    Rate this question:

  • 7. 

    What is ‘short int’ in C programming?

    • A.

      A basic data type

    • B.

      Qualifier

    • C.

      Modifier

    • D.

      ‘short’ is qualifier, ‘int’ is basic data type.

    Correct Answer
    D. ‘short’ is qualifier, ‘int’ is basic data type.
    Explanation
    In C programming, 'short int' is a data type that combines the 'short' qualifier with the 'int' basic data type. The 'short' qualifier is used to reduce the range of values that can be stored in the variable, while the 'int' data type is a basic data type used to represent integer values. Therefore, 'short int' is a combination of a qualifier and a basic data type.

    Rate this question:

  • 8. 

    Does this code compile without error(s)?    // no header files included    int main()    {        int k;        {            int k;            for (k = 0; k < 10; k++);   // there’s a semicolon in the end!        }     return 0;    }

    • A.

      Yes

    • B.

      No

    • C.

      Depends on the compiler

    • D.

      Depends on the C standard you are using

    Correct Answer
    A. Yes
    Explanation
    Header files are only required for inbuilt fuctions(like: printf(),scanf()).
    Data-types(like:int, float etc) are already known to the compiler.
    When variable ‘k’ is declared second time, it’s declared inside another block, hence no contradiction of having two variables with same name. Also, putting a ‘;’ at the end of ‘for’ loop takes it as an empty statement.

    Rate this question:

  • 9. 

    What is the output of this C code?    #include     int main()    {     int i;     scanf(“%d”, &i);    // inputting 071     printf(“%d”, i);     return 0;         }

    • A.

      071

    • B.

      71

    • C.

      57

    • D.

      56

    Correct Answer
    B. 71
    Explanation
    When we declare or assign an int variable starting with 0, the compiler considers it as Hexadecimal value. But when, printf() prints, it prints it in its decimal equivalent. ‘071’ in Hexadecimal = ‘57’ in decimal But if we take input by scanf() it ignore the first digit '0'.

    Rate this question:

  • 10. 

    What is the output of this C code?    #include<stdio.h>    int main()    {     printf(“%d”, printf(“Hello 2018! ”));     return 0; }        

    • A.

      Compile time error

    • B.

      Hello 2018!

    • C.

      12

    • D.

      Hello 2018! 12

    Correct Answer
    D. Hello 2018! 12
    Explanation
    printf() function returns the number of characters it has printed.

    Rate this question:

  • 11. 

    What is the output of this C code?   #include <stdio.h>    int main()    {     if(printf("foo"))      switch(printf("bar"))       while(printf("infinite"));         return 0;         }

    • A.

      Foobarinfiniteinfiniteinfinite………∞

    • B.

      Foobar

    • C.

      Foobarinfinite

    • D.

      Compile-time error

    Correct Answer
    B. Foobar
    Explanation
    Since printf() return the no. of characters printed so, in if it would be 3 and ‘foo’ is printed. Similarly, in switch it would also be 3, due to ‘bar’. Also, switch will search for ‘case 3’ but, it doesn’t find any ‘case 3’, so it comes out of switch and hence program terminates.

    Rate this question:

  • 12. 

    What is the output of this C code?   #include <stdio.h>    #define square(x) x*x    int main()    {     int a = 2;     int sqr = square(a+1);     printf(“%d”,sqr);     return 0;         }

    • A.

      3

    • B.

      4

    • C.

      5

    • D.

      6

    Correct Answer
    C. 5
    Explanation
    #define replaces the square(x) with x*x with the value of ‘x’ provided before compiling the code.
    Therefore, square(a+1) would become a+1*a+1, which is 2+1*2+1 = 2+2+1 = 5

    Rate this question:

  • 13. 

    What will be the value of d in the following program? #include int main() {   int a = 10, b = 5, c = 5;   int d;   d = b + (c == a);   printf("%d", d); }

    • A.

      Syntax Error

    • B.

      1

    • C.

      5

    • D.

      10

    Correct Answer
    C. 5
    Explanation
    In the given program, the value of d is determined by the expression "b + (c == a)". Here, (c == a) is a comparison expression which evaluates to false because c is not equal to a. In C language, false is represented by 0 and true is represented by 1. So, the expression becomes "b + 0" which is equal to b. Therefore, the value of d will be 5, as the value of b is 5.

    Rate this question:

  • 14. 

    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;    }

    • A.

      Compile time error

    • B.

      -1 1

    • C.

      1 -1

    • D.

      Implementation defined

    Correct Answer
    B. -1 1
    Explanation
    The code initializes the variable i with the value 3. It then performs integer division between i and -2, resulting in l being assigned the value -1. It also calculates the remainder of the division, which is assigned to k. Since the remainder of dividing 3 by -2 is 1, k is assigned the value 1. The printf statement then prints the values of l and k, resulting in the output -1 1.

    Rate this question:

  • 15. 

    What is the Output of this C code? #include <stdio.h>    int main()    {        int a = 10;        if (a == a--)            printf("TRUE 1\t");        a = 10;        if (a == --a)            printf("TRUE 2\t");    }

    • A.

      TRUE 1

    • B.

      TRUE 2

    • C.

      TRUE 1 TRUE 2

    • D.

      Compiler Dependent

    Correct Answer
    D. Compiler Dependent
    Explanation
    The output of this C code is Compiler Dependent. This is because the behavior of the code depends on how the compiler evaluates the expressions and the order in which the side effects of the expressions are applied. In the first if statement, the expression "a == a--" compares the value of a with the value of a before it is decremented. Some compilers may evaluate the expression as true because the value of a is copied before it is decremented, while others may evaluate it as false because the value of a is decremented before the comparison. In the second if statement, the expression "a == --a" compares the value of a with the value of a after it is decremented. Again, the behavior may vary depending on the compiler.

    Rate this question:

Quiz Review Timeline +

Our quizzes are rigorously reviewed, monitored and continuously updated by our expert board to maintain accuracy, relevance, and timeliness.

  • Current Version
  • Mar 21, 2023
    Quiz Edited by
    ProProfs Editorial Team
  • Sep 11, 2018
    Quiz Created by
    500060884
Back to Top Back to top
Advertisement
×

Wait!
Here's an interesting quiz for you.

We have other quizzes matching your interest.