C And C++ Questions: 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 Vikas Rajpoot
V
Vikas Rajpoot
Community Contributor
Quizzes Created: 1 | Total Attempts: 115
| Attempts: 115 | Questions: 10
Please wait...
Question 1 / 10
0 %
0/100
Score 0/100
1. What should be used to move the cursor to a new line?

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.

Submit
Please wait...
About This Quiz
C And C++ Questions: Trivia Quiz! - Quiz

Dive into the fundamentals of C and C++ with this trivia quiz! Test your knowledge on general programming concepts, syntax specifics, and code execution outcomes. Perfect for learners looking to assess and enhance their programming skills in these widely-used languages.

Personalize your quiz and earn a certificate with your name on it!
2. 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); }

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.

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

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.

Submit
4. 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 }

Explanation

not-available-via-ai

Submit
5. Which two statements are true for variables in C++?

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

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

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.

Submit
7. C is a:

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.

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

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.

Submit
9. Match the following:
Submit
10. 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";   }               }  

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.

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 18, 2018
    Quiz Created by
    Vikas Rajpoot
Cancel
  • All
    All (10)
  • Unanswered
    Unanswered ()
  • Answered
    Answered ()
What should be used to move the cursor to a new line?
What is the output of following program ...
Following program prints ...
In which line there is an error in the program...
Which two statements are true for variables in C++?
What is the output of following program ...
C is a:
What is the output of the following program...
Match the following:
What is the output of the following program....
Alert!

Advertisement