1.
C is a:
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.
2.
What should be used to move the cursor to a new line?
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.
3.
Which two statements are true for variables in C++?
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++.
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;
}
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.
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 }
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"; }
}
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.
7.
What is the output of the following program
#include<stdio.h>
void main( )
{ int a = 2;
if( a== 2 || ++a )
{ printf("%d", a); }
}
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.
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);
}
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.
9.
What is the output of following program
#include<stdio.h>
void main( )
{
int i =6;
do{
--i;
printf(" %d ",i);
} while(i>0);
}
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.