31 / 87
What is the output of the following C Program?
#include
void main()
{
printf("sizeof (void *) = %d \n", sizeof( void *));
printf("sizeof (int *) = %d \n", sizeof(int *));
printf("sizeof (double *) = %d \n", sizeof(double *));
printf("sizeof(struct unknown *) = %d \n", sizeof(struct unknown *));
}
Asizeof (void *) = 4 sizeof (int *) = 4 sizeof (double *) = 4 sizeof(struct unknown *) = 4
Bsizeof (void *) = 2 sizeof (int *) = 2 sizeof (double *) = 4 sizeof(struct unknown *) = 4
Csizeof (void *) = 4 sizeof (int *) = 4 sizeof (double *) = 2 sizeof(struct unknown *) = 4
DCompilation Error
Answer: Option A
Explanation:The pointer to any type is of same size.
Workspace
32 / 87
To print out a and b given below, which printf() statement will be used ?
float a = 3.14;
double b = 3.14;
Aprintf("%f%f', a, b);
Bprintf("%Lf%f', a, b);
Cprintf ("%Lf%Lf', a, b);
Dprintf("%f%Lf', a, b);
Answer: Option A
Explanation:Here, in every option we see that there is a missing terminating " character, which will result to an error.
Hence, to print the values of a and b, the code should be-
printf("%f%f",a,b);
This will give the output as 3.1400003.140000.
Workspace
33 / 87
To scan float a and double b, which scanf() statement will be used?
Ascanf("%f%f", &a, &b);
Bscanf("%f%Lf', &a, &b);
Cscanf ("%Lf%Lf', &a, &b);
Dscan{ ("%f%lf', &a, &b);
Answer: Option D
Explanation:We want to scan float a and double b.
Option A is incorrect because it will scan both the variables as float.
Option B is incorrect as here variable b will be scanned as long-double type, but we want b to be double type.
Option C is incorrect because here both the variables will be scanned as long-double type.
Option D is incorrect because it should be 'scanf' and not 'scan{', which will create an error. If we correct this then variable a will be scanned as float type and variable b will be scanned as double type.
Workspace
34 / 87
The Below statement in 'C' prints.
printf("%c", 200)
Aprints 200
Bprints the ascii equivalent of 200
Cprints garbage
Dnone of these
Answer: Option B
Explanation:Here, 200 is an integer value, and we are printing a character. Hence, the output will be the character corresponding to the given integer value 200.
For ASCII code 200, the printable character will be "╚ ".
Hence, the correct option is B.
Workspace
35 / 87
C language is available for which of the following Operating System?
ADOS
BWindows
CUnix
DAll of these
Answer: Option D
Explanation:Here is no explanation for this answer
Workspace
36 / 87
How will you print \n on the screen ?
Aprintf(“\n”);
Becho \\n;
Cprintf(“\n”);
Dprintf(\\n);
Answer: Option D
Explanation:The statement printf("\\n"); prints '\n' on the screen.
Workspace
37 / 87
Assignment operator targets to _____
Ar-value
Bl-value
Cboth
DNone
Answer: Option B
Explanation:Assignment operators are used to assign the the values present on the right-hand side to whatever is present on the left-hand side of the operator. The left-hand side can be a variable or a pointer, and the right-hand side can be a variable, a constant, an expression or a function call.
For example-
a=5; //assigns '5' to 'a'.
On the other hand, 5=a; //error.
Very often in C, we use the terminology of l-value in error messages. It basically refers to the operands present on the left-hand side of the assignment operator. It can be a variable or a pointer, but should not be a constant.
Hence, from the above theory, we can conclude for sure that assignment operator targets to L-value.
Workspace
38 / 87
What will be output of the following "c" code?
#include
void main() {
printf("ABCDEFG \n");
printf(4+"ABCDEFG\n");
printf("ABCDEFG\n"+4);
printf("%c\n", "ABCDEFG" [4]);
printf("%c\n", 4["ABCDEFG"]);
}
AABCDEFG EFG EFG E E
BCompilation Error
CNo output No Error
DABCDEFG ABCDEFG ABCDEFG ABCDEFG ABCDEFG
Answer: Option A
Explanation:Line 3 is simple that it will print ABCDEFG.
Line 4 and 5 will result to the same output, i.e, it will print the characters from 4th index to (n-1)th index or 6th index. Hence, printing EFG for both the lines.
Line 6 and 7 will also result to the same output, i.e, it will print the character at 4th index position. Hence, printing E for both the lines.
Hence, the output will be ABCDEFG EFG EFG E E.
Workspace
39 / 87
What will be output of the following "c" code?
#include
void main( )
{
int i;
printf("%d", scanf("%d", &i));
}
If input of is given by keyboard is 10.
A10
B1
CCompilation Error
DNone of these
Answer: Option B
Explanation:Here, no. of values that are scanned is 1, and we know that printf() function returns the no. of characters as argument. Hence, output will be 1.
Workspace
40 / 87
What will be output of the following "c" code?
#include
void main() {
int i =400, j = 300;
printf("%d %d %d %d ");
}
AGarbage Values
Bstack overflow
C400 300
D300 400
Answer: Option A
Explanation:In the printf() function we are just printing values, but have it's not specified what values are we actually printing. Therefore, in such a case, it is going to print garbage values.
Workspace