Basics Of C Language: Trivia Quiz!

Reviewed by Editorial Team
The ProProfs editorial team is comprised of experienced subject matter experts. They've collectively created over 10,000 quizzes and lessons, serving over 100 million users. Our team includes in-house content moderators and subject matter experts, as well as a global network of rigorously trained contributors. All adhere to our comprehensive editorial guidelines, ensuring the delivery of high-quality content.
Learn about Our Editorial Process
| By 500060884
5
500060884
Community Contributor
Quizzes Created: 2 | Total Attempts: 441
| Attempts: 224 | Questions: 15
Please wait...
Question 1 / 15
0 %
0/100
Score 0/100
1. Which of the following is not a valid variable name declaration in the C programming language?

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.

Submit
Please wait...
About This Quiz
Basics Of C Language: Trivia Quiz! - Quiz

Dive into the Basics of C Language with this trivia quiz! Test your understanding of variable names, code outputs, and conditional logic in C. Ideal for beginners aiming... see moreto solidify their programming skills and grasp essential concepts effectively. see less

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

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.

Submit
3. 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;         }

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

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

Explanation

printf() function returns the number of characters it has printed.

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

Explanation

In a function a variable can take the same name as that of the function

Submit
6. What is 'short int' in C programming?

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.

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

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.

Submit
8. 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;    }

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".

Submit
9. 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;    }

Explanation

Here, ‘,’ operator in while() will act as LOGICAL OR operator i.e. (i

Submit
10. 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;    }

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.

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

Explanation

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

Submit
12. 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;    }

Explanation

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

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

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'.

Submit
14. 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); }

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.

Submit
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");    }

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.

Submit
View My Results

Quiz Review Timeline (Updated): Mar 21, 2023 +

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
Cancel
  • All
    All (15)
  • Unanswered
    Unanswered ()
  • Answered
    Answered ()
Which of the following is not a valid variable name declaration in the...
What is the output of this C code? ...
What is the output of this C code? ...
What is the output of this C code?...
What will happen if the below program is executed?...
What is 'short int' in C programming?
What is the output of this C code? ...
What is the output of the following C code? ...
What is the output of the following C code?...
Does this code compile without error(s)? ...
What is the output of the following C code?...
What will be the output of this C code?...
What is the output of this C code? ...
What will be the value of d in the following program? ...
What is the Output of this C code? ...
Alert!

Advertisement