1.
)#include
void call(int,int,int);
int main(){
int a=10;
call(a,a++,++a);
return 0;
}
void call(int x,int y,int z){
printf("%d %d %d",x,y,z);
}
Correct Answer
B. 12 11 11
Explanation
The correct answer is 12 11 11. In the main function, the variable a is initially assigned the value 10. The call function is then called with the arguments a, a++, and ++a.
When the call function is executed, the values of the arguments are passed to the parameters x, y, and z respectively. The value of a is 12 at this point because of the pre-increment operation (++a) in the argument list.
However, the post-increment operation (a++) in the argument list causes the value of a to be incremented after it is passed to the call function. Therefore, the value of y is 11.
The value of x is still 10 because it was passed by value before any increment operations.
So, the output of the call function is 12 11 11.
2.
#include<stdio.h>
int main(){
int a=-20;
int b=-3;
printf("%d",a%b);
return 0;
}
Correct Answer
B. -2
Explanation
The code snippet defines two variables, 'a' and 'b', with values -20 and -3 respectively. The expression 'a%b' calculates the remainder when 'a' is divided by 'b'. In this case, -20 divided by -3 gives a quotient of 6 and a remainder of -2. Therefore, the output of the program will be -2.
3.
#include<stdio.h>
int main(){
char *url="c:\tc\bin\rw.c";
printf("%s",url);
return 0;
}
Correct Answer
E. W.c in
Explanation
The given code is a C program that prints the value of the variable "url" using the printf function. The variable "url" is assigned the value "c:\tc\bin\rw.c". The printf function then prints this value, which is "w.c in". Therefore, the correct answer is "w.c in".
4.
Which of the following is not derived data type in c?
Correct Answer
C. Enumeration
Explanation
An enumeration is not a derived data type in C. Derived data types are created by combining or modifying existing data types. Examples of derived data types in C include arrays, functions, and pointers. However, an enumeration is a user-defined data type that consists of a set of named values. It is used to define a list of constants that can be assigned to a variable. Therefore, the correct answer is enumeration.
5.
The function which is used to move the file pointer to any desired location within a file?
Correct Answer
A. Fseek()
Explanation
The fseek() function is used to move the file pointer to any desired location within a file. It allows us to set the position indicator of the file stream to a specific offset from a reference point. This reference point can be the beginning, end, or current position of the file. By using fseek(), we can easily navigate through a file and perform operations at specific positions.
6.
#include<stdio.h>
int main(){
int a=15,b=10,c=5;
if(a>b>c )
printf("True");
else
printf("False");
return 0;
}
Correct Answer
B. False
Explanation
The code snippet compares three variables a, b, and c using the greater than operator (>). Since 15 is not greater than 10, the condition in the if statement evaluates to false. Therefore, the code will execute the else block and print "False".
7.
What will be the output when you will execute following c code?
#include<stdio.h>
void main(){
char arr[7]="Network";
printf("%s",arr);
}
Correct Answer
C. Garbage value
Explanation
The output of the given C code will be "Network". The character array "arr" is initialized with the string "Network" which is 7 characters long. When the printf statement is executed, it will print the string stored in the "arr" array. Therefore, the output will be "Network" and not garbage value.
8.
#include<stdio.h>
int main(){
const int i=5;
i++;
printf("%d",i);
return 0;
}
Correct Answer
D. Compiler error
Explanation
The given code will result in a compiler error. This is because the variable "i" is declared as a constant using the "const" keyword, which means its value cannot be changed. However, in the code, there is an attempt to increment the value of "i" using the "i++" statement, which is not allowed for a constant variable. Therefore, the code will not compile successfully.
9.
#include<stdio.h>
int main()
{
int i = 1;
switch(i)
{
printf("Hello\n");
case 1:
printf("Hi\n");
break;
case 2:
printf("\nBye\n");
break;
}
return 0;
}
Correct Answer
C. Hi
Explanation
The code provided will not compile successfully due to a syntax error. The printf statement "Hello" is placed outside of any case block, which is not allowed in a switch statement. Therefore, the code will produce a compilation error.
10.
# include<stdio.h>
# define a 10
void foo();
main()
{
printf("%d..",a);
foo();
printf("%d",a);
}
void foo()
{
#undef a
#define a 50
}
Correct Answer
A. 10..10
Explanation
The code first defines a constant variable "a" with a value of 10 using the "#define" directive. It then calls the "foo()" function, which undefines the previous definition of "a" and redefines it with a new value of 50. However, since the "foo()" function is called after the first printf statement, the first printf statement will still print the original value of "a", which is 10. Therefore, the output will be "10..10".