1.
Point out the correct statements are correct about the program below?
#include
int main()
{
char ch;
while(x=0;x<=255;x++)
printf("ASCII value of %d character %c\n", x, x);
return 0;
}
Correct Answer
D. Error: while statement missing
Explanation
The given code has a syntax error because the while statement is missing the condition. The correct syntax for the while statement is while(condition). Since the condition is missing, the code will not compile and will result in an error.
2.
Which of the following is the correct usage of conditional operators used in C?
Correct Answer
C. Max = a>b ? a>c?a:c:b>c?b:c
Explanation
The correct usage of conditional operators in C is demonstrated in the given answer. The expression "max = a>b ? a>c?a:c:b>c?b:c" assigns the maximum value among three variables a, b, and c to the variable max. The first part of the expression "a>b ? a>c?a:c" checks if a is greater than b, and if true, it further checks if a is greater than c. If both conditions are true, a is assigned to max. Otherwise, c is assigned to max. If the first condition "a>b" is false, the second part of the expression "b>c?b:c" checks if b is greater than c. If true, b is assigned to max. Otherwise, c is assigned to max.
3.
If a function contains two return statements successively, the compiler will generate warnings. Yes/No?
Correct Answer
A. Yes
Explanation
When a function contains two return statements successively, it means that both return statements are executed one after the other. This can lead to a situation where only the first return statement is actually reached and the second return statement is never executed. The compiler generates warnings in such cases because it indicates a potential logic error in the code. It is generally considered good practice to have only one return statement in a function to ensure clarity and avoid confusion.
4.
What will be the output of the program ?
#include
int main()
{
float arr[] = {12.4, 2.3, 4.5, 6.7};
printf("%d\n", sizeof(arr)/sizeof(arr[0]));
return 0;
}
Correct Answer
B. 4
Explanation
The program calculates the size of the array by dividing the total size of the array (sizeof(arr)) by the size of each element in the array (sizeof(arr[0])). Since the array is declared as a float array, the size of each element is 4 bytes. Therefore, the output of the program will be 4, indicating that there are 4 elements in the array.
5.
Is there any difference int the following declarations?
int fun(int arr[]);
int fun(int arr[2]);
Correct Answer
B. No
Explanation
There is no difference in the two declarations. Both declarations are specifying a function named "fun" that takes an integer array as a parameter. The size of the array is not specified in either declaration.
6.
Does there exist any way to make the command-line arguments available to other functions without passing them as arguments to the function?
Correct Answer
A. Yes
Explanation
There are several ways to make command-line arguments available to other functions without passing them as arguments. One common approach is to use global variables, where the command-line arguments are stored in a global variable that can be accessed by any function within the program. Another approach is to use a configuration file, where the command-line arguments are stored and can be read by any function that needs them. Additionally, some programming languages provide built-in mechanisms for accessing command-line arguments without passing them as arguments to functions.
7.
What function should be used to free the memory allocated by calloc()?
Correct Answer
C. Free();
Explanation
The function that should be used to free the memory allocated by calloc() is free(). The calloc() function is used to allocate memory for an array of elements, and the free() function is used to deallocate that memory once it is no longer needed. By calling free(), the memory previously allocated by calloc() is released and can be reused for other purposes.
8.
What do the following declaration signify?
void *cmp();
Correct Answer
C. Cmp is a function that return a void pointer.
Explanation
The declaration "void *cmp();" signifies that cmp is a function that returns a void pointer. The use of "*" before cmp indicates that cmp is a pointer, and the "void" before the "*" indicates that the pointer points to a void type. Since the function is declared to return a void pointer, it means that the function does not have a specific return type and can return a pointer to any type.
9.
What will be the output of the program?
#include
int main()
{
char huge *near *far *ptr1;
char near *far *huge *ptr2;
char far *huge *near *ptr3;
printf("%d, %d, %d\n", sizeof(**ptr1), sizeof(ptr2), sizeof(*ptr3));
return 0;
}
Correct Answer
A. 4, 4, 4
Explanation
The correct answer is 4, 4, 4. This is because the sizeof operator is used to determine the size in bytes of a data type or variable. In this program, **ptr1 refers to the value pointed to by the pointer ptr1, which is a char type. Therefore, sizeof(**ptr1) will return 4, as a char data type typically occupies 1 byte of memory. Similarly, sizeof(ptr2) and sizeof(*ptr3) will also return 4, as they are both pointers and typically occupy 4 bytes of memory on most systems.
10.
We can modify the pointers "source" as well as "target".
Correct Answer
A. True
Explanation
The given statement is true because it states that we have the ability to modify the pointers "source" and "target". This implies that we can change the values or addresses that these pointers are pointing to. Therefore, the correct answer is true.
11.
Will the program outputs "IndiaBIX.com"? #includeint main(){ char str1[] = "IndiaBIX.com"; char str2[20]; strncpy(str2, str1, 8); printf("%s", str2); return 0;}
Correct Answer
B. No
Explanation
The program will not output "IndiaBIX.com" because the strncpy function is used to copy a specified number of characters from one string to another. In this case, it will copy the first 8 characters from str1 to str2. Therefore, the program will output only "IndiaBIX" as str2 will only contain those 8 characters.
12.
Which of the following cannot be checked in a switch-case statement?
Correct Answer
C. Float
Explanation
A switch-case statement is used to check the value of a variable against multiple cases. It allows for branching based on the value of the variable. In this case, the correct answer is "Float" because switch-case statements can only be used with integer values, character values, and enumerated types. Float values are not allowed as switch-case expressions because they are not discrete values that can be easily compared.
13.
Which of the following statements are correct about the program?
#include
int main()
{
int x = 30, y = 40;
if(x == y)
printf("x is equal to y\n");
else if(x > y)
printf("x is greater than y\n");
else if(x < y)
printf("x is less than y\n")
return 0;
}
Correct Answer
A. Error: Statement missing
Explanation
The correct answer is "Error: Statement missing". This is because there is a missing semicolon at the end of the line where the printf statement is located. This results in a syntax error, as the compiler expects a statement to be present before the return statement.
14.
Are the following two statement same?
1. a <= 20 ? (b = 30): (c = 30);
2. (a <=20) ? b : (c = 30);
Correct Answer
B. No
Explanation
The two statements are not the same. In the first statement, if a is less than or equal to 20, then b is assigned the value 30; otherwise, c is assigned the value 30. In the second statement, if a is less than or equal to 20, then the value of b is returned; otherwise, c is assigned the value 30. The difference lies in the assignment of values.
15.
What will be the output of the program ?#include int main(){ char *str; str = "%d\n"; str++; str++; printf(str-2, 300); return 0;}
Correct Answer
D. 300
Explanation
The program initializes a character pointer 'str' and assigns it the value "%d". The pointer is then incremented twice. The printf function is called with the argument 'str-2', which points to the original value of 'str'. The format specifier "%d" is used to format the argument 300, so the output of the program will be 300.
16.
The library function used to reverse a string is ____
Correct Answer
B. Strrev()
Explanation
The correct answer is strrev(). This is because the strrev() function is a library function that is used to reverse a string. It takes a string as input and returns the reversed string as output.
17.
Point out the error in the program?
struct emp
{
int ecode;
struct emp *e;
};
Correct Answer
C. No Error
Explanation
The given program does not have any error. The structure "emp" is correctly declared with an integer variable "ecode" and a pointer variable "e" of type "struct emp".
18.
In Turbo C/C++ under DOS if we want that any wild card characters in the command-line arguments should be appropriately expanded, are we required to make any special provision?
Correct Answer
A. Yes
Explanation
In Turbo C/C++ under DOS, if we want wild card characters in the command-line arguments to be appropriately expanded, we are required to make a special provision. This means that we need to write code or include a function that handles the expansion of wild card characters in the command-line arguments. Without this special provision, the wild card characters will not be expanded automatically.
19.
Bitwise | can be used to multiply a number by powers of 2.
Correct Answer
B. No
Explanation
The statement is incorrect. The bitwise OR operator (|) is not used to multiply a number by powers of 2. Instead, it is used to perform a bitwise OR operation on the individual bits of two numbers. To multiply a number by powers of 2, the bitwise left shift operator (
20.
What does the following declaration signify?
int *f();
Correct Answer
B. F is a function returning pointer to an int.
Explanation
The declaration "int *f();" signifies that f is a function that returns a pointer to an int. The syntax "int *" indicates that the return type of the function is a pointer, and "f()" indicates that f is a function. Therefore, the correct answer is "f is a function returning pointer to an int."
21.
Which of the following is the correct order of evaluation for the below expression?
z = x + y * z / 4 % 2 - 1
Correct Answer
A. * / % + - =
Explanation
The correct order of evaluation for the given expression is as follows: first, the multiplication operation is performed (y * z), then the division operation is performed (y * z / 4), next the modulus operation is performed (y * z / 4 % 2), then the addition operation is performed (x + y * z / 4 % 2), and finally the subtraction operation is performed (x + y * z / 4 % 2 - 1).
22.
Will the printf() statement print the same values for any values of a?#includeint main(){ float a; scanf("%f", &a); printf("%f\n", a+a+a); printf("%f\n", 3*a); return 0;}
Correct Answer
A. Yes
Explanation
The printf() statement will print the same values for any values of a because both printf() statements are calculating and printing the same expression, which is a+a+a and 3*a respectively. Therefore, the output will be the same regardless of the value of a.
23.
What will be the output of the program if the array begins 1200 in memory?#include int main(){ int arr[]={2, 3, 4, 1, 6}; printf("%u, %u, %u\n", arr, &arr[0], &arr); return 0;}
Correct Answer
B. 1200, 1200, 1200
Explanation
The program is printing the memory addresses of the array and its first element. Since the array begins at memory address 1200, the first output is 1200. The second output is also 1200 because the address of the first element of the array is the same as the address of the array itself. The third output is also 1200 because the address of the array is the same as the address of the first element of the array.
24.
What will be the output of the program?
#include
int main()
{
printf(5+"IndiaBIX\n");
return 0;
}
Correct Answer
C. BIX
Explanation
The program will output "BIX". The expression "5+"IndiaBIX"" adds the number 5 to the address of the string "IndiaBIX". This results in the program printing the characters starting from the 5th position of the string, which is "BIX".
25.
Point out the error in the program?
struct emp
{
int ecode;
struct emp e;
};
Correct Answer
A. Error: in structure declaration
Explanation
The error in the program is in the structure declaration. The structure "emp" contains a member "e" of the same structure type "emp". This creates a recursive definition of the structure, which is not allowed in C. To fix the error, the member "e" should be declared as a pointer to the structure "emp" instead of directly including the structure itself.
26.
The maximum combined length of the command-line arguments including the spaces between adjacent arguments is
Correct Answer
D. It may vary from one operating system to another
Explanation
The maximum combined length of command-line arguments can vary from one operating system to another. Different operating systems may have different limits on the maximum length of command-line arguments. Therefore, it is not possible to determine a fixed maximum length without considering the specific operating system being used.
27.
What will be the output of the program?
#include
int main()
{
const c = -11;
const int d = 34;
printf("%d, %d\n", c, d);
return 0;
}
Correct Answer
B. -11, 34
Explanation
The program will output "-11, 34". The variable "c" is declared as a constant with a value of -11, and the variable "d" is declared as a constant integer with a value of 34. The printf statement will print the values of "c" and "d" as "%d" placeholders, resulting in the output "-11, 34".
28.
Point out the error in the following program.
#include
int main()
{
char str[] = "IndiaBIX";
printf("%.#s %2s", str, str);
return 0;
}
Correct Answer
D. No error
Explanation
The given program does not contain any errors.
29.
Which of the following fopen statements is illegal?
Correct Answer
D. None of the mentioned
Explanation
All of the given fopen statements are legal. The fopen function is used to open a file in different modes such as "r" for reading, "w" for writing, etc. In this case, the first statement opens a file named "abc.txt" in read mode, the second statement opens a file located at "/home/user1/abc.txt" in write mode, and the third statement opens a file named "abc" in write mode. Therefore, none of the fopen statements are illegal.
30.
What is the output of this C code? #include int main() { FILE *fp = stdout; int n; fprintf(fp, "%d\n ", 45); fprintf(stderr, "%d ", 65); return 0; }
Correct Answer
A. 45 65
Explanation
The code includes the standard input/output library and defines a main function. It declares a FILE pointer variable named 'fp' and initializes it to the standard output stream 'stdout'. It also declares an integer variable 'n'. The code then uses the fprintf function to print the value 45 followed by a line break to the 'fp' stream, which is the standard output. It also uses fprintf to print the value 65 to the standard error stream 'stderr'. Finally, the code returns 0. Therefore, the output of the code will be "45 65", with the numbers separated by a space.
31.
What is the output of this C code? #include int main() { char n[] = "hellonworld!"; char s[13]; sscanf(n, "%s", s); printf("%s\n", s); return 0; }
Correct Answer
C. hello
Explanation
The code declares a character array "n" with the value "hellonworld!" and another character array "s" with a size of 13. The sscanf function is used to read a string from "n" and store it in "s". The format specifier "%s" is used to read a string until a whitespace character is encountered. The printf function then prints the value of "s", which is "hello" as the whitespace character after "hello" in "n" terminates the string. Therefore, the output of the code is "hello".
32.
What is the output of this C code? #include int main() { short int i; scanf("%hd", &i); printf("%hd", i); return 0; }
Correct Answer
C. Whatever user types
Explanation
The code snippet uses the scanf function to read input from the user and store it in the variable "i". The format specifier "%hd" is used to indicate that the input should be treated as a short integer. However, the code does not provide the address of the variable "i" to the scanf function, which results in undefined behavior. In this case, the behavior will depend on the compiler and system being used. Therefore, the output will be whatever the user types, but the code may produce unexpected results or errors.
33.
What is the output of this C code? #include int main() { char *p = NULL; char *q = 0; if (p) printf(" p "); else printf("nullp"); if (q) printf("q\n"); else printf(" nullq\n"); }
Correct Answer
A. Nullp nullq
Explanation
The output of this C code is "nullp nullq". This is because the variables p and q are both assigned the value NULL, which represents a null pointer. In the if statements, the condition (p) and (q) both evaluate to false since the values of p and q are null. Therefore, the else statements are executed and the strings "nullp" and "nullq" are printed respectively.
34.
What is the output of this C code? #include int main() { int i = 10; void *p = &i; printf("%d\n", (int)*p); return 0; }
Correct Answer
A. Compile time error
Explanation
The given C code will result in a compile time error. This is because the line "void *p = &i;" is trying to assign the address of an integer variable to a void pointer without any typecasting. Void pointers can hold the address of any data type, but they need to be explicitly typecasted to the correct data type before dereferencing. Since the code is trying to dereference the void pointer without typecasting, it will result in a compile time error.
35.
Property of external variable to be accessed by any source file is called by C90 standard as
Correct Answer
A. External linkage
Explanation
The C90 standard refers to the property of an external variable being accessible by any source file as "external linkage". This means that the variable can be accessed and used by other source files in the program. Other options such as "external scope", "global scope", and "global linkage" do not accurately describe this specific property.
36.
What is the output of this C code? #include int main() { printf("%d\n", srand(9000)); return 0; }
Correct Answer
A. Compile time error
Explanation
The code includes the header file "stdio.h" which contains the declaration of the printf() function. However, it does not include the header file "stdlib.h" which contains the declaration of the srand() function. This leads to a compile-time error because the compiler does not recognize the srand() function.
37.
What is the output of this C code? #include void main() { #define max 45 max = 32; printf("%d", max); }
Correct Answer
C. Compile time error
Explanation
The code tries to redefine the macro "max" with a new value of 32 after it has already been defined as 45. This is not allowed in C, as macros are meant to be constants and cannot be changed once defined. Therefore, the code will result in a compile time error.
38.
What is the output of the code given below?
#include
int main()
{
char a[1][5] = {"hello"};
printf("%s", a[0]);
return 0;
}
Correct Answer
C. Undefined behaviour
Explanation
The code given above has undefined behavior because the character array `a` is declared with a size of 1x5, but the string "hello" requires 6 characters (including the null terminator). This means that the string "hello" will overflow the bounds of the array, resulting in undefined behavior.
39.
The precedence of arithmetic operators is (from highest to lowest)
Correct Answer
A. %, *, /, +, –
Explanation
The precedence of arithmetic operators determines the order in which mathematical operations are performed. In this case, the correct answer is "%, *, /, +, –". This means that the modulus operator (%) has the highest precedence, followed by multiplication (*), division (/), addition (+), and subtraction (-). This order ensures that calculations involving these operators are performed correctly according to mathematical conventions.
40.
Which of the following data type will throw an error on modulus operation(%)?
Correct Answer
D. Float
Explanation
The modulus operation (%) is used to find the remainder when one number is divided by another. It can only be performed on integer types, such as char, short, and int. However, when trying to perform the modulus operation on a float data type, it will throw an error because float is a floating-point type and not an integer type.
41.
What is the output of this C code? #include int main() { int a = 10; double b = 5.6; int c; c = a + b; printf("%d", c); }
Correct Answer
A. 15
Explanation
The code declares an integer variable "a" with a value of 10 and a double variable "b" with a value of 5.6. It then declares an integer variable "c" without initializing it. The expression "a + b" adds the value of "a" and the truncated value of "b" (5), resulting in 15. The printf statement then outputs the value of "c" as an integer, which is 15.
42.
Which of the following is not an arithmetic operation?
Correct Answer
C. A != 10;
Explanation
The expression "a != 10" is not an arithmetic operation because it is a comparison operation. The "!=" operator checks if the value of "a" is not equal to 10. Arithmetic operations involve mathematical calculations such as addition, subtraction, multiplication, and division. In this case, the other expressions "a *= 10", "a /= 10", and "a %= 10" involve multiplication, division, and modulus operations respectively, making them arithmetic operations.
43.
The name of the variable used in one function cannot be used in another function.
Correct Answer
B. False
Explanation
The statement is false because variables used in one function can be accessed and used in another function as long as they are in the same scope or if they are passed as arguments to the other function. Variables can have global scope, which means they can be accessed from anywhere within the program, or local scope, which means they can only be accessed within the specific function they are defined in.
44.
What is the output of this C code?
#include
int main()
{
int x = 1, y = 0, z = 3;
x > y ? printf("%d", z) : return z;
}
Correct Answer
C. Compile time error
Explanation
The code will result in a compile time error. This is because the ternary operator (?:) requires both the true and false expressions to have the same data type. In this case, the true expression is printf("%d", z), which is of type int, while the false expression is return z, which is a statement and not an expression. Therefore, the code will fail to compile.
45.
Which of the following is a ternary operator?
Correct Answer
C. ?:
Explanation
The ternary operator, represented by "?:" in programming languages, is a conditional operator that takes three operands. It evaluates a condition and returns one of two values based on the result of the condition. The first operand is the condition to be evaluated, the second operand is the value to be returned if the condition is true, and the third operand is the value to be returned if the condition is false. In this case, "?:" is the only option that represents a ternary operator.
46.
Associativity of an operator are:
Correct Answer
D. Both (a) and (b)
Explanation
The explanation for the given correct answer is that the associativity of an operator can be either right to left or left to right, depending on the operator. Some operators associate from right to left, meaning that the right operand is evaluated first, while others associate from left to right, meaning that the left operand is evaluated first. Therefore, the correct answer is both (a) and (b), as some operators have right to left associativity and others have left to right associativity.
47.
Which of the following operators has the lowest precedence?
Correct Answer
D. ,
Explanation
The operator with the lowest precedence among the given options is the comma operator (,). The comma operator evaluates both of its operands and returns the value of the second operand. It is typically used to separate multiple expressions within a larger expression. The other operators listed, "!=" (not equal), "&&" (logical AND), and "?: " (ternary conditional), have higher precedence than the comma operator.
48.
Can variable I be accessed by functions in another source file?
#include
int i;
int main()
{
printf("%d\n", i);
}
Correct Answer
A. 0
Explanation
The variable i can be accessed by functions in another source file because it is declared outside of any function, making it a global variable. Global variables can be accessed by any function within the same program.
49.
What is the output of this C code?
#include
void main()
{
int n;
scanf("%d", n);
printf("%d", n);
}
Correct Answer
C. Nothing
Explanation
The code is trying to read an integer from the user using the scanf() function and store it in the variable 'n'. However, there is a mistake in the code. The second argument of scanf() function should be the address of the variable where the input should be stored. In this case, it should be '&n' instead of 'n'. Since the correct address is not passed to scanf(), it will result in undefined behavior and can cause a segmentation fault or any other unpredictable output. In this case, the output will be nothing because the value of 'n' is not initialized and it will print garbage value.
50.
What function should be used to free the memory allocated by calloc()?
Correct Answer
C. Free();
Explanation
The correct answer is "free();". The function free() is used to deallocate the memory that was allocated using functions like malloc(), calloc(), or realloc(). It takes a pointer to the memory block as its argument and releases the memory, making it available for reuse.