1.
What will be the output of the program?
#include
#include
int main()
{
float n=1.54;
printf("%f, %f\n", ceil(n), floor(n));
return 0;
}
Correct Answer
A. 2.000000, 1.000000
Explanation
The program uses the ceil() and floor() functions to calculate the ceiling and floor values of the variable n, which is initialized as 1.54. The ceil() function returns the smallest integer that is greater than or equal to the given value, while the floor() function returns the largest integer that is less than or equal to the given value. In this case, the ceil() function will round up 1.54 to 2.000000, and the floor() function will round down 1.54 to 1.000000. Therefore, the output of the program will be "2.000000, 1.000000".
2.
What will be the output of the program?
#include
int main()
{
float d=2.25;
printf("%e,", d);
printf("%f,", d);
printf("%g,", d);
printf("%lf", d);
return 0;
}
Correct Answer
C. 2.250000e+000, 2.250000, 2.25, 2.250000
Explanation
The program will output the number "2.250000e+000" in scientific notation, followed by "2.250000" with six decimal places, then "2.25" in standard notation, and finally "2.250000" with six decimal places again. This is because the first printf statement uses the "%e" format specifier, which prints the number in scientific notation. The second printf statement uses the "%f" format specifier, which prints the number with six decimal places. The third printf statement uses the "%g" format specifier, which automatically chooses between scientific notation and standard notation depending on the magnitude of the number. The fourth printf statement uses the "%lf" format specifier, which is the same as "%f" but is used for double precision floating point numbers.
3.
Point out the error in the program
#include
int main()
{
int i;
#if A
printf("Enter any number:");
scanf("%d", &i);
#elif B
printf("The number is odd");
return 0;
}
Correct Answer
A. Error: unexpected end of file because there is no matching #endif
Explanation
The error in the program is that there is no matching #endif for the #if statement. This causes an unexpected end of file error.
4.
What will be the output of the program (Turbo C in 16-bit platform DOS)?
#include
#include
int main()
{
char *str1 = "India";
char *str2 = "BIX";
char *str3;
str3 = strcat(str1, str2);
printf("%s %s\n", str3, str1);
return 0;
}
Correct Answer
B. IndiaBIX IndiaBIX
Explanation
The program is using the strcat() function to concatenate str2 at the end of str1. However, str1 is a string literal and is stored in read-only memory. Trying to modify a string literal results in undefined behavior. In this case, it seems that the program is able to concatenate str2 with str1, but it is not guaranteed to work correctly. The output of the program is "IndiaBIX IndiaBIX", but it could have been different or even resulted in an error.
5.
Which of the following statements correct about the below program?
#include
int main()
{
union a
{
int i;
char ch[2];
};
union a u1 = {512};
union a u2 = {0, 2};
return 0;
}
1: u2 CANNOT be initialized as shown.
2: u1 can be initialized as shown.
3: To initialize char ch[] of u2 '.' operator should be used.
4: The code causes an error 'Declaration syntax error'
Correct Answer
C. 1, 2, 3
Explanation
1: u2 can be initialized as shown because it is a union and the initialization syntax used is valid.
2: u1 can be initialized as shown because it is a union and the initialization syntax used is valid.
3: To initialize char ch[] of u2, the '.' operator should be used instead of ',' operator.
6.
What will be the output of the program?
#include
int get();
int main()
{
const int x = get();
printf("%d", x);
return 0;
}
int get()
{
return 20;
}
Correct Answer
C. 20
Explanation
The program will output 20. This is because the function get() returns the value 20, which is then assigned to the constant variable x. When the value of x is printed using printf(), it will display 20.
7.
Point out the error in the program.
#include
#include
int fun(const union employee *e);
union employee
{
char name[15];
int age;
float salary;
};
const union employee e1;
int main()
{
strcpy(e1.name, "A");
fun(&e1);
printf("%s %d %f", e1.name, e1.age, e1.salary);
return 0;
}
int fun(const union employee *e)
{
strcpy((*e).name, "B");
return 0;
}
Correct Answer
B. Error: cannot convert parameter 1 from 'const char[15]' to 'char *'
Explanation
The error in the program is that the function fun() is defined to take a pointer to a constant union employee as its parameter. However, in the main() function, the strcpy() function is used to modify the name of the e1 object, which is a violation of the const qualifier. This results in the error "cannot convert parameter 1 from 'const char[15]' to 'char *'".
8.
Point out the error in the following program.
#include
void display(int (*ff)());
int main()
{
int show();
int (*f)();
f = show;
display(f);
return 0;
}
void display(int (*ff)())
{
(*ff)();
}
int show()
{
printf("IndiaBIX");
}
Correct Answer
C. No error and prints "IndiaBIX"
Explanation
The program does not have any errors and will print "IndiaBIX". The function display() takes a function pointer as a parameter and calls the function using the pointer. In the main() function, the function show() is declared and assigned to the function pointer f. The display() function is then called with the function pointer as an argument, which will execute the show() function and print "IndiaBIX".
9.
Point out the error, if any in the program.
#include
int main()
{
int a = 10, b;
a >=5 ? b=100: b=200;
printf("%d\n", b);
return 0;
}
Correct Answer
C. Error: L value required for b
Explanation
The error in the program is that the ternary operator is trying to assign a value to a variable (b) that is not an l-value. An l-value refers to a location in memory that can be assigned a value. In this case, the ternary operator is trying to assign a value to b, but b does not have a memory location. To fix this error, the variable b should be declared before the ternary operator statement.
10.
What will be the output of the program?
#include
int main()
{
int i=4, j=-1, k=0, w, x, y, z;
w = i || j || k;
x = i && j && k;
y = i || j &&k;
z = i && j || k;
printf("%d, %d, %d, %d\n", w, x, y, z);
return 0;
}
Correct Answer
D. 1, 0, 1, 1
Explanation
The program first evaluates the logical OR operation between i, j, and k. Since i is non-zero, the result of this operation is 1.
Next, the program evaluates the logical AND operation between i, j, and k. Since j is negative, the result of this operation is 0.
Then, the program evaluates the logical OR operation between i and the logical AND operation between j and k. Since i is non-zero and j is negative, the result of this operation is 1.
Finally, the program evaluates the logical AND operation between i and j, and then the logical OR operation between the result and k. Since i is non-zero and j is negative, the result of this operation is 1.
Therefore, the output of the program is 1, 0, 1, 1.
11.
Macros have a local scope.
Correct Answer
B. False
Explanation
Macros do not have a local scope. In programming, a local scope refers to a portion of code where variables and functions can only be accessed and used within that specific portion. However, macros are expanded by the preprocessor before the code is compiled, and they are not bound by any scope rules. Macros can be accessed and used throughout the entire program, making them have a global scope.
12.
Is this a correct way for NULL pointer assignment?
int i=0;
char *q=(char*)i;
Correct Answer
B. No
Explanation
No, this is not a correct way for NULL pointer assignment. In the given code, the variable "i" is of type int and it is being casted to a char pointer "q". This means that the value of "i" is being interpreted as a memory address, which is incorrect. A NULL pointer should be assigned using the literal value "NULL" or by assigning the address 0 to the pointer.
13.
What will be the output of the program if the array begins at 65472 and each integer occupies 2 bytes?
#include
int main()
{
int a[3][4] = {1, 2, 3, 4, 4, 3, 2, 1, 7, 8, 9, 0};
printf("%u, %u\n", a+1, &a+1);
return 0;
}
Correct Answer
B. 65480, 65496
Explanation
The output of the program will be 65480, 65496.
In the printf statement, we are printing the addresses of two different elements of the array.
- The expression "a+1" gives the address of the second element of the array, which is a[1][0]. Since each integer occupies 2 bytes, the address of a[1][0] will be 65472 + (1 * 2) = 65474.
- The expression "&a+1" gives the address of the next block of memory after the entire array. Since the array is a 3x4 matrix and each integer occupies 2 bytes, the size of the array is 3 * 4 * 2 = 24 bytes. Therefore, the address of the next block of memory will be 65472 + 24 = 65496.
14.
What will be the output of the program ?
#include
#include
int main()
{
char sentence[80];
int i;
printf("Enter a line of text\n");
gets(sentence);
for(i=strlen(sentence)-1; i >=0; i--)
putchar(sentence[i]);
return 0;
}
Correct Answer
B. The sentence will get printed in reverse order
Explanation
The program prompts the user to enter a line of text and stores it in the character array "sentence". It then uses a for loop to iterate through the characters in the array in reverse order, starting from the last character (strlen(sentence)-1) and ending at the first character (i >= 0). Inside the loop, each character is printed using the putchar function. Therefore, the output of the program will be the sentence entered by the user, but in reverse order.
15.
What will be the output of the program ?
#include
struct course
{
int courseno;
char coursename[25];
};
int main()
{
struct course c[] = { {102, "Java"},
{103, "pHP"},
{104, "DotNet"} };
printf("%d ", c[1].courseno);
printf("%s\n", (*(c+2)).coursename);
return 0;
}
Correct Answer
A. 103 DotNet
Explanation
The program defines a structure called "course" with two members: courseno (an integer) and coursename (an array of characters). In the main function, an array of course structures called "c" is initialized with three elements, each containing a courseno and coursename.
The first printf statement prints the courseno of the second element in the array, which is 103.
The second printf statement prints the coursename of the third element in the array, using pointer arithmetic to access the member. It prints "DotNet", which is the coursename of the third element.
So, the output of the program will be "103 DotNet".
16.
On executing the below program what will be the contents of 'target.txt' file if the source file contains a line "To err is human"?
#include
int main()
{
int i, fss;
char ch, source[20] = "source.txt", target[20]="target.txt", t;
FILE *fs, *ft;
fs = fopen(source, "r");
ft = fopen(target, "w");
while(1)
{
ch=getc(fs);
if(ch==EOF)
break;
else
{
fseek(fs, 4L, SEEK_CUR);
fputc(ch, ft);
}
}
return 0;
}
Correct Answer
B. Trh
Explanation
The program opens a source file named "source.txt" and a target file named "target.txt". It then reads characters from the source file one by one using the getc() function. If the character is not the end of file (EOF), it moves the file pointer 4 positions ahead using fseek() and writes the character to the target file using fputc(). This process continues until the end of the source file is reached. Therefore, the contents of the "target.txt" file will be "Trh" which are the characters that were read and written from the source file.
17.
What will be the output of the program (sample.c) given below if it is executed from the command line (Turbo C in DOS)?
cmd> sample 1 2 3
/* sample.c */
#include
int main(int argc, char *argv[])
{
int j;
j = argv[1] + argv[2] + argv[3];
printf("%d", j);
return 0;
}
Correct Answer
C. Error
Explanation
The program will output "Error". This is because the argv array stores command line arguments as strings, and the expression argv[1] + argv[2] + argv[3] is attempting to add three string pointers together, which is not a valid operation. Therefore, the program will result in a compilation error.
18.
What will be the output of the program?
#include
int main()
{
int x=1, y=1;
for(; y; printf("%d %d\n", x, y))
{
y = x++ <= 5;
}
printf("\n");
return 0;
}
Correct Answer
A. A. 2 1
3 1
4 1
5 1
6 1
7 0
Explanation
The program starts with initializing x and y to 1. The for loop has an empty initialization statement and the loop continues as long as y is non-zero. Inside the loop, the value of y is updated to the result of the comparison x++
19.
Which of the following range is a valid long double (Turbo C in 16 bit DOS OS) ?
Correct Answer
A. 3.4E-4932 to 1.1E+4932
Explanation
The correct answer is 3.4E-4932 to 1.1E+4932. This range represents the valid values for a long double data type in Turbo C in a 16-bit DOS operating system. The lower limit of 3.4E-4932 indicates the smallest possible positive value that can be stored, while the upper limit of 1.1E+4932 represents the largest possible positive value. Any value outside of this range would not be considered a valid long double in this specific context.
20.
What will be the output of the program?
#include
#include
int main()
{
int i=0;
i++;
if(i<=5)
{
printf("IndiaBIX");
exit(1);
main();
}
return 0;
}
Correct Answer
D. Prints "IndiaBIx"
Explanation
The program will enter the if statement and print "IndiaBIX" once. However, since the program calls the main function recursively, it will create an infinite loop and keep printing "IndiaBIX" indefinitely. Therefore, the correct answer is "Infinite loop".
21.
What will be the output of the program ?
#include
int main()
{
int i, a[] = {2, 4, 6, 8, 10};
change(a, 5);
for(i=0; i<=4; i++)
printf("%d, ", a[i]);
return 0;
}
void change(int *b, int n)
{
int i;
for(i=0; i *(b+1) = *(b+i)+5;
}
Correct Answer
B. 2, 15, 6, 8, 10
Explanation
The program first declares an array "a" with 5 elements. Then, it calls the function "change" passing the array "a" and the size of the array as arguments. In the "change" function, it iterates over the elements of the array and assigns the value of each element to the next element plus 5. Finally, in the main function, it prints the elements of the array "a". The output of the program will be "2, 15, 6, 8, 10".
22.
What will be the output of the program ?
#include
int main()
{
enum status {pass, fail, absent};
enum status stud1, stud2, stud3;
stud1 = pass;
stud2 = absent;
stud3 = fail;
printf("%d %d %d\n", stud1, stud2, stud3);
return 0;
}
Correct Answer
C. 0, 2, 1
Explanation
The program declares an enumeration type called "status" with three possible values: pass, fail, and absent. It then declares three variables of type "status" called stud1, stud2, and stud3. stud1 is assigned the value pass, stud2 is assigned the value absent, and stud3 is assigned the value fail. Finally, the program prints the values of stud1, stud2, and stud3, which are 0, 2, and 1 respectively.
23.
Which of the following statements are correct about the program?
#include
char *fun(unsigned int num, int base);
int main()
{
char *s;
s=fun(128, 2);
s=fun(128, 16);
printf("%s\n",s);
return 0;
}
char *fun(unsigned int num, int base)
{
static char buff[33];
char *ptr = &buff[sizeof(buff)-1];
*ptr = '\0';
do
{
*--ptr = "0123456789abcdef"[num %base];
num /=base;
}while(num!=0);
return ptr;
}
Correct Answer
A. It converts a number to a given base
Explanation
The program provided is a function called "fun" that takes a number and a base as input and converts the number to the given base. The function uses a static character array "buff" with a size of 33 to store the converted number. It then uses a pointer "ptr" to point to the last element of "buff" and assigns a null character '\0' to it. The function then uses a do-while loop to iterate through the number and convert it to the given base by using the remainder of the number divided by the base to access the corresponding character in the string "0123456789abcdef". The converted number is stored in reverse order in "buff". Finally, the function returns the pointer "ptr" which points to the converted number. Therefore, the correct answer is "It converts a number to a given base".
24.
Point out the correct statement will let you access the elements of the array using 'p' in the following program?
#include
#include
int main()
{
int i, j;
int(*p)[3];
p = (int(*)[3])malloc(3*sizeof(*p));
return 0;
}
Correct Answer
C. For(i=0; i<3; i++) { for(j=0; j<3; j++) printf("%d", p[i][j]); }
Explanation
The correct statement that will let you access the elements of the array using 'p' in the given program is "for(i=0; i<3; i++)". This statement will iterate over the array 'p' and allow access to each element in the array.
25.
Point out the error in the following program.
#include
#include
int main()
{
char str1[] = "Learn through IndiaBIX\0.com", str2[120];
char *p;
p = (char*) memccpy(str2, str1, 'i', strlen(str1));
*p = '\0';
printf("%s", str2);
return 0;
}
Correct Answer
D. No error and prints "Learn through Indi"
Explanation
The program does not have any errors and it will print "Learn through Indi". The memccpy function is used to copy characters from one string to another until a specified character is encountered. In this program, the memccpy function is used to copy characters from str1 to str2 until the character 'i' is encountered. The pointer p is then assigned the value of the character 'i' in str2. Finally, the null character '\0' is added to the end of str2. The printf statement then prints the contents of str2, which is "Learn through Indi".
26.
What does the following segment of code do?
fprintf(fp, “Copying!”);
Correct Answer
A. It writes “Copying!” into the file pointed by fp
Explanation
The given segment of code uses the fprintf function to write the string "Copying!" into the file pointed by the variable fp.
27.
FILE reserved word is
Correct Answer
D. It is a type name defined in stdio.h
Explanation
The FILE reserved word is a type name defined in stdio.h. In C programming, FILE is used to declare objects that handle input and output operations. It represents the structure used to control streams in C, such as files. It provides functions and variables to perform operations like reading, writing, and manipulating files. By including stdio.h, the FILE type becomes available for use in the program.
28.
What is the output of this C code?
#include
int main(). {. char *s = "myworld"; int i = 9;
printf("%*s", i, s);
}
Correct Answer
B. Myworld(note: spaces to the left of myworld)
Explanation
The code uses the printf function to print the string "myworld" with a specified width of 9 characters. The * in the format specifier %*s is used to specify the width as an argument. Since the width is set to 9, the output will have 9 characters. However, since the string "myworld" only has 7 characters, there will be 2 spaces added to the left of the string to fill the remaining width. Therefore, the output will be " myworld" with 2 spaces before "myworld".
29.
What is the output of this C code?
#include
int main()
{
int i = 10;
void *p = &i;
printf("%f\n", *(float*)p);
return 0;
}
Correct Answer
D. 0.000000
Explanation
The code will result in undefined behavior. This is because the code is attempting to interpret the memory address of an integer variable as a float pointer and then dereference it to print the value. However, the memory layout and interpretation of the data will be different for an integer and a float, leading to unpredictable results.
30.
What is the output of this C code?
#include .
int *i;.
int main()
{
if (i == NULL)
printf("true\n");
return 0;
}
Correct Answer
A. true
Explanation
The output of this C code is "true". This is because the variable "i" is not assigned any value, so it is uninitialized and its value is NULL. The if statement checks if "i" is equal to NULL, which is true in this case. Therefore, the code inside the if statement is executed and "true" is printed.
31.
Which of the following declaration is illegal?
Correct Answer
D. Char[] str = “Best C programming classes by Sanfoundry”;
Explanation
The correct answer is "char[] str = “Best C programming classes by Sanfoundry”;". This declaration is illegal because when declaring an array, the size of the array must be specified. In this declaration, the size of the array is missing, which makes it invalid.
32.
Comment on the output of this C code?
#include
struct temp
{
int a;
int b;
int c;
};
main()
{
struct temp p[] = {{1, 2, 3}, {4, 5, 6}, {7, 8, 9}};
}
Correct Answer
A. No Compile time error, generates an array of structure of size 3
Explanation
The given C code does not have any compile time errors and it generates an array of structure of size 3. The struct temp has three members: a, b, and c. The main function declares an array of struct temp called p and initializes it with three elements, each containing values for a, b, and c. Therefore, the code will compile successfully and create an array of structure of size 3.
33.
What is the output of this C code?
#include
struct student
{
};
void main()
{
struct student s[2];
printf("%d", sizeof(s));
}
Correct Answer
D. 0
Explanation
The code defines an empty structure called "student" and creates an array of two "student" objects called "s". The sizeof operator is then used to determine the size of the "s" array, which is 0. This is because the structure "student" has no members, so it does not occupy any memory. Therefore, the output of the code is 0.
34.
What is the output of this C code?
#include
int *f();
int main()
{
int *p = f();
printf("%d\n", *p);
}
int *f()
{
int *j = (int*)malloc(sizeof(int));
*j = 10;
return j;
}
Correct Answer
A. 10
Explanation
The output of this C code is 10. The function `f()` is called in the `main()` function and it returns a pointer to an integer. Inside the `f()` function, memory is allocated for an integer using `malloc()`, and the value 10 is assigned to it. This memory location is then returned and assigned to the pointer variable `p` in the `main()` function. The value of the integer pointed to by `p` is then printed, which is 10.
35.
Which of the following causes an error?
Correct Answer
D. All of the menioned
Explanation
All of the mentioned options can cause an error. Trying to read a file that doesn't exist will result in a file not found error. Inability to write data in a file can occur due to insufficient permissions or a full disk. Failure to allocate memory with malloc can lead to a memory allocation error, especially if there is not enough memory available. Therefore, all of these situations can cause errors.
36.
What is the difference between %e and %g?
Correct Answer
B. %e always formats in the format [-]m.dddddd or [-]m.dddddE[+|-]xx where no.of ds are optional and output formatting depends on the argument.
Explanation
The correct answer is that %e always formats in the format [-]m.dddddd or [-]m.dddddE[+|-]xx where no.of ds are optional and output formatting depends on the argument. This means that %e will display the number in scientific notation, with the option to specify the number of decimal places. The output formatting will vary based on the argument provided.
37.
What is the output of this C code(when 1 is entered)?
#include
void main()
{
double ch;
printf("enter a value btw 1 to 2:");
scanf("%lf", &ch);
switch (ch)
{
case 1:
printf("1");
break;
case 2:
printf("2");
break;
}
}
Correct Answer
A. Compile time error
Explanation
The code will result in a compile time error because the variable "ch" is declared as a double, but the switch statement only accepts integer values. Since the input is expected to be a decimal value between 1 and 2, it cannot be directly used in the switch statement.
38.
What is the output of this C code(When 1 is entered)?
#include
void main()
{
char *ch;
printf("enter a value btw 1 to 3:");
scanf("%s", ch);
switch (ch)
{
case "1":
printf("1");
break;
case "2":
printf("2");
break;
}
}
Correct Answer
B. Compile time error
Explanation
The code will result in a compile time error because the switch statement is comparing a char pointer (ch) with string literals ("1" and "2"). In C, string literals are represented as arrays of characters, so they cannot be directly compared with a char pointer. To fix this error, the code should use single quotes ('1' and '2') instead of double quotes when comparing characters.
39.
What is the output of this C code?
#include
void main()
{
char *p = calloc(100, 1);
p = "welcome";
printf("%s\n", p);
}
Correct Answer
D. Welcome
Explanation
The output of this C code is "welcome". The code first allocates memory of size 100 bytes using the calloc function and assigns the address of the allocated memory to the pointer variable p. However, the code then reassigns the pointer p to point to the string "welcome". So, when the printf function is called to print the value of p, it will print the string "welcome".
40.
C preprocessors can have compiler specific features.
Correct Answer
A. True
Explanation
C preprocessors can have compiler specific features because preprocessors are part of the compiler and are responsible for performing text substitution before the actual compilation process begins. Different compilers may have their own specific features and extensions that can be used in the preprocessing stage. These features can include conditional compilation, macro expansion, and file inclusion, among others. Therefore, the statement is true.
41.
What is the output of the code given below?
#include
int main()
{
printf("%d ", 1);
goto l1;
printf("%d ", 2);
l1:goto l2;
printf("%d ", 3);
l2:printf("%d ", 4);
}
Correct Answer
A. 1 4
Explanation
The code starts by printing "1" using the printf() function. Then, it encounters a goto statement which jumps to the label "l1". This means that the code after the goto statement is skipped. After jumping to "l1", it encounters another goto statement which jumps to the label "l2". Again, the code after this goto statement is skipped. Finally, it reaches the printf() statement which prints "4". Therefore, the output of the code is "1 4".
42.
What is the output of this C code?
#include
const int a = 1, b = 2;
int main()
{
int x = 1;
switch (x)
{
case a:
printf("yes ");
case b:
printf("no\n");
break;
}
}
Correct Answer
D. Compile time error
Explanation
The code will result in a compile time error because the switch statement is using variables a and b as case values, which are declared as const. In C, the case values in a switch statement must be constant expressions, and variables declared as const do not qualify as constant expressions. Therefore, the code will not compile.
43.
What is the output of this C code?
#include
int main()
{
int i = 0, j = 1;
int *a[] = {&i, &j};
printf("%d", *a[0]);
return 0;
}
Correct Answer
C. 0
Explanation
The output of this C code is 0. This is because the variable "a" is an array of pointers to integers, and it is initialized with the addresses of variables "i" and "j". When we access the value at index 0 of "a" using *a[0], it gives us the value stored at the address of "i", which is 0.
44.
What is the output of this C code?
#include
void main()
{
struct student
{
int no;
char name[20];
};
struct student s;
s.no = 8;
printf("%d", s.no);
}
Correct Answer
D. 8
Explanation
The code defines a structure named "student" with two members - "no" of type int and "name" of type char array. It then declares a variable "s" of type student. The value 8 is assigned to the "no" member of the "s" variable. Finally, the code prints the value of "s.no", which is 8. Therefore, the output of the code is 8.
45.
Sin(x) returns
Correct Answer
A. sine of x where x is in radians
Explanation
The function sin(x) returns the sine of x, where x is in radians. The sine function is a mathematical function that calculates the ratio of the length of the side opposite to an angle in a right triangle to the length of the hypotenuse. In this case, the function sin(x) calculates the sine of x when x is given in radians, which is the standard unit of measurement for angles in mathematics.
46.
What is the output of this C code?
#include
int main()
{
int i = 0;
for (foo(); i == 1; i = 2)
printf("In for loop\n");
printf("After loop\n");
}
int foo()
{
return 1;
}
Correct Answer
A. After loop
Explanation
The correct answer is "After loop". This is because the condition in the for loop is i == 1, but the initial value of i is 0. Therefore, the condition is false and the code inside the for loop is never executed. As a result, only the printf statement "After loop" is executed.
47.
What is the output of this C code?
#include
void main()
{
int i = 0;
if (i == 0)
{
printf("Hello");
continue;
}
}
Correct Answer
D. Compile time error
Explanation
The given code will result in a compile time error. The reason for this is that the "continue" statement is used outside of a loop. The "continue" statement is used to skip the rest of the current iteration of a loop and move to the next iteration. Since there is no loop present in the code, the "continue" statement is invalid and causes a compile time error.
48.
What is the output of this C code?
#include
int main()
{
int x = 0;
if (x == 1)
if (x == 0)
printf("inside if\n");
else
printf("inside else if\n");
else
printf("inside else\n");
}
Correct Answer
C. Inside else
Explanation
The output of this C code is "inside else". This is because the value of x is 0, so the first if statement is not true. Therefore, the program moves to the else statement and prints "inside else".
49.
What is the output of this C code?
#include
int main()
{
int x = 0;
if (x == 1)
if (x >= 0)
printf("true\n");
else
printf("false\n");
}
Correct Answer
D. No print statement
Explanation
The correct answer is "No print statement". This is because the if statement checks if x is equal to 1, and since x is initialized to 0, the condition is false. Therefore, the code inside the if statement is not executed, and there is no print statement in the code outside of the if statement.
50.
C preprocessors can have compiler specific features.
Correct Answer
A. True
Explanation
C preprocessors can have compiler specific features because preprocessors are part of the compiler and can vary from compiler to compiler. These features may include compiler-specific directives, macros, or other functionalities that are not standardized across different compilers. Therefore, the availability and behavior of these features can depend on the specific compiler being used.