C And C++ Questions: 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 Vikas Rajpoot
V
Vikas Rajpoot
Community Contributor
Quizzes Created: 1 | Total Attempts: 107
Questions: 10 | Attempts: 107

SettingsSettingsSettings
C And C++ Questions: Trivia Quiz! - Quiz

.


Questions and Answers
  • 1. 

    C is a:

    • A.

      Client-side scripting language

    • B.

      General purpose programming language

    • C.

      Movie making program

    • D.

      All

    Correct Answer
    B. General purpose programming language
    Explanation
    The correct answer is "General purpose programming language" because C is a programming language that is widely used for developing a variety of applications, including system software, embedded systems, and high-performance applications. It is not limited to a specific domain or purpose, making it a versatile language for various programming tasks.

    Rate this question:

  • 2. 

    What should be used to move the cursor to a new line?

    • A.

      \a

    • B.

      \t

    • C.

      \n

    • D.

      \r

    Correct Answer
    C. \n
    Explanation
    The correct answer is "\n". This is the escape sequence used in most programming languages to represent a new line character. When this escape sequence is encountered, it moves the cursor to the beginning of the next line.

    Rate this question:

  • 3. 

    Which two statements are true for variables in C++?

    • A.

      The variable name may be same as the keyword in c++/c

    • B.

      Variables must have a data type

    • C.

      Variables must be declared before their use

    • D.

      Variables are pre-processor directives

    Correct Answer(s)
    B. Variables must have a data type
    C. Variables must be declared before their use
    Explanation
    In C++, variables must have a data type because the compiler needs to know the size and type of data that the variable can hold. This allows the compiler to allocate the appropriate amount of memory for the variable. Additionally, variables must be declared before their use to inform the compiler about the existence and type of the variable. If a variable is used without being declared, the compiler will generate an error. Therefore, both of these statements are true for variables in C++.

    Rate this question:

  • 4. 

    Following program prints  #include<stdio.h>  int main() {      int i = 65;      char j = 'A';      if(i==j)             printf(" C is WOW  \n");     else              printf(" C is a headache \n");      return 0; }  

    • A.

      C is WOW

    • B.

      C is a headache

    • C.

      C is WOO

    • D.

      Error

    Correct Answer
    A. C is WOW
    Explanation
    The program compares the integer variable i with the character variable j. Since the ASCII value of 'A' is 65, which is equal to the value of i, the condition i==j is true. Therefore, the program will execute the printf statement "C is WOW" and print it as the output.

    Rate this question:

  • 5. 

    In which line there is an error in the program 1 #include<stdio.h> 2 int main() 3 { 4       int size; 5       scanf("%d",&size); 6       int arr[size]; 7       for(int i =0 ; i<=size ; i++) 8       { 9                    scanf("%d" , &arr[i]); 10                   printf("%d", arr[i]);    11      } 12      return 0; 13 }

    • A.

      1

    • B.

      5

    • C.

      6

    • D.

      9

    Correct Answer
    C. 6
  • 6. 

    What is the output of the following program. #include<iostream.h> void main() {          int a = 5;          if(a = 10)            {   cout << " You are correct ";         }           else               {     cout << " You are incorrect";   }               }  

    • A.

      You are correct

    • B.

      You are incorrect

    • C.

      None

    • D.

      Compilation error

    Correct Answer
    A. You are correct
    Explanation
    The output of the program will be "You are correct". This is because the if statement checks if the value of 'a' is equal to 10. However, there is a mistake in the code where the assignment operator '=' is used instead of the equality operator '=='. So, the value of 'a' is assigned 10 and the condition in the if statement is true, resulting in the "You are correct" message being printed.

    Rate this question:

  • 7. 

    What is the output of the following program #include<stdio.h> void main( ) {      int a = 2;        if( a== 2 || ++a )        {     printf("%d", a);    } }

    • A.

      4

    • B.

      1

    • C.

      2

    • D.

      3

    Correct Answer
    C. 2
    Explanation
    The output of the program is 2. This is because the condition in the if statement is true since a is indeed equal to 2. Therefore, the code inside the if statement is executed, which is the printf statement that prints the value of a, which is 2.

    Rate this question:

  • 8. 

    What is the output of following program  #include<stdio.h> void main( ) {        int a =5;        int *p = &a;         printf("%d %d ", a,*p);        *p = 7;          printf("%d %d", a,*p); }

    • A.

      55 77

    • B.

      55 55

    • C.

      57 57

    • D.

      77 55

    Correct Answer
    A. 55 77
    Explanation
    The program declares an integer variable 'a' with a value of 5. It then declares a pointer variable 'p' and assigns the address of 'a' to it. The first printf statement prints the value of 'a' and the value pointed to by 'p', which is both 5. Then, the value pointed to by 'p' is changed to 7. The second printf statement prints the updated value of 'a', which is 7, and the value pointed to by 'p', which is also 7. Therefore, the output of the program is 55 77.

    Rate this question:

  • 9. 

    What is the output of following program  #include<stdio.h> void main( ) {       int i =6;       do{              --i;              printf(" %d ",i);          } while(i>0); }  

    • A.

      543210

    • B.

      123456

    • C.

      654321

    • D.

      54321

    Correct Answer
    A. 543210
    Explanation
    The program starts with the value of i being 6. It then enters a do-while loop where it decrements i by 1 and prints its value until i becomes less than or equal to 0. Therefore, the output of the program is 543210.

    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 18, 2018
    Quiz Created by
    Vikas Rajpoot
Advertisement
×

Wait!
Here's an interesting quiz for you.

We have other quizzes matching your interest.