1.
What will the function rewind() do?
Correct Answer
C. Reposition the file pointer to begining of that line
Explanation
The function rewind() is used to reposition the file pointer to the beginning of the file. It does not reposition the file pointer to a character reverse or to the end of the file. Therefore, the correct answer is "Reposition the file pointer to the beginning of that line."
2.
In C, if you pass an array as an argument to a function, what actually gets passed?
Correct Answer
C. Base address of the array
Explanation
When you pass an array as an argument to a function in C, only the base address of the array gets passed. This means that the function will have access to the memory location where the array starts, allowing it to access and modify the elements of the array using pointer arithmetic. By having the base address, the function can effectively work with the entire array, not just the first element or the last element.
3.
Which standard library function will you use to find the last occurance of a character in a string in C?Â
Correct Answer
D. Strrchr()
Explanation
The strrchr() function is the correct answer because it is a standard library function in C that is used to find the last occurrence of a character in a string. It takes two arguments - the string in which to search for the character, and the character to search for. The function returns a pointer to the last occurrence of the character in the string, or NULL if the character is not found.
4.
What will be the size of the following structure?
#include
struct temp
{
int a[10];
char p;
};
Correct Answer
D. 44
Explanation
The size of the structure is determined by the sum of the sizes of its individual members. In this case, the structure has an array of integers with a size of 10 integers, which would be 10 * sizeof(int). It also has a character variable, which has a size of sizeof(char). Therefore, the total size of the structure would be the sum of these two sizes, which is 10 * sizeof(int) + sizeof(char). Calculating this would result in the answer of 44.
5.
What is the similarity between a structure, union and enumeration?Â
Correct Answer
B. All of them let you define new data types
Explanation
All of the options mentioned - structure, union, and enumeration - allow the user to define new data types. These data types can be used to create variables that can store different kinds of values. Structures allow the user to combine different data types into a single entity, unions allow the user to define a data type that can hold different types of values at different times, and enumerations allow the user to define a set of named values for a variable. Therefore, all three options allow the user to define new data types.
6.
What will happen if in a C program you assign a value to an array element whose subscript exceeds the size of array?
Correct Answer
C. The program may crash if some important data gets overwritten.
Explanation
If a value is assigned to an array element whose subscript exceeds the size of the array, it means that the program is accessing memory outside the bounds of the array. This can lead to overwriting important data that is stored in adjacent memory locations. As a result, the program may crash or produce unexpected behavior.
7.
Which among the following is right?Â
Correct Answer
C. Sizeof(struct stemp*) = sizeof(union utemp*) = sizeof(char *)
Explanation
The answer is "sizeof(struct stemp*) = sizeof(union utemp*) = sizeof(char *)". This means that the size of a pointer to a struct, a pointer to a union, and a pointer to a char are all the same. The size of a pointer depends on the architecture and the compiler being used, so it is not possible to determine the exact size without more information.
8.
What do the following declaration signify?Â
char **argv;
Correct Answer
B. Argv is a pointer to a char pointer.
Explanation
The declaration "char **argv" signifies that "argv" is a pointer to a char pointer. This means that "argv" is a variable that stores the memory address of a pointer to a char variable. It is commonly used in C and C++ programs to store command-line arguments passed to a program.
9.
What do the following declaration signify?Â
int (*pf)();
Correct Answer
C. Pf is a pointer to a function which return int
Explanation
The declaration "int (*pf)();" signifies that pf is a pointer to a function which returns an integer. This means that pf can be used to store the address of a function that returns an integer value.
10.
What do the following declaration signify?Â
char *arr[10];
Correct Answer
A. Arr is a array of 10 character pointers.
Explanation
The declaration "char *arr[10]" signifies that arr is an array of 10 character pointers. This means that arr is a collection of 10 memory addresses, where each address points to a character value.
11.
How will you free the memory allocated by the following program?Â
#include
#include
#define MAXROW 3
#define MAXCOL 4
int main()
{
int **p, i, j;
p = (int **) malloc(MAXROW * sizeof(int*));
return 0;
}
Correct Answer
D. Â free(p);
Explanation
The correct answer is "free(p)". This is because the program allocates memory using the malloc() function, which dynamically allocates memory on the heap. In order to free this memory and prevent memory leaks, the free() function should be used. The argument passed to free() should be the pointer to the memory that was allocated, in this case "p". Therefore, the correct way to free the memory allocated by the program is to use the free(p) statement.
12.
What is x in the following program?
#include
int main()
{
typedef char (*(*arrfptr[3])())[10];
arrfptr x;
return 0;
}
Correct Answer
C. X is an array of three function pointers
Explanation
The given program declares x as an array of three function pointers. The typedef statement creates a new type arrfptr, which is an array of three pointers to functions that return a pointer to an array of ten characters. The declaration arrfptr x; then creates an array named x of type arrfptr, which means x is an array of three function pointers.
13.
In the following code what is 'P'?Â
typedef char *charp;
const charp P;
Correct Answer
A. P is a constant
Explanation
The code declares 'P' as a constant. The 'typedef' keyword is used to create an alias 'charp' for the type 'char *' (pointer to char). The 'const' keyword is then used to make 'P' a constant, meaning its value cannot be changed once it is assigned. Therefore, the correct answer is that 'P' is a constant.
14.
How is search done in #include and #include "somelibrary.h" according to C standard?Â
Correct Answer
D. For both, search for ‘somelibrary’ is done in implementation-defined places
Explanation
According to the C standard, when #include is used, the search for 'somelibrary' is done in implementation-defined places. Similarly, when #include "somelibrary.h" is used, the search is also done in implementation-defined places. Therefore, the correct answer states that the search for 'somelibrary' is done in implementation-defined places for both cases.
15.
What is the sequence for preprocessor to look for the file within ?
Correct Answer
A. The predefined location then the current directory
Explanation
The preprocessor first looks for the file in the predefined location, which is a specific location set by the system or compiler. If the file is not found in the predefined location, then the preprocessor searches for it in the current directory, which is the directory where the program is being compiled from. This sequence ensures that the preprocessor checks the commonly used and system-defined locations first before looking in the current directory.
16.
What is stderr?Â
Correct Answer
C. Standard error streams
Explanation
Stderr stands for standard error streams. In computer programming, it refers to the stream where error messages and diagnostic information are typically sent. It is a way for programs to communicate errors or exceptional conditions to the user or to other parts of the program. By separating the standard error stream from the standard output stream, developers can easily distinguish between regular program output and error messages, allowing for better error handling and debugging.
17.
Input/output function prototypes and macros are defined in which header file?Â
Correct Answer
C. Stdio.h
Explanation
The correct answer is stdio.h. This header file contains the necessary function prototypes and macros for input/output operations in C programming language. It provides functions like printf() and scanf() for formatted output and input respectively.
18.
What do the 'c' and 'v' in argv stands for?Â
Correct Answer
C. 'c' means argument count 'v' means argument vector
Explanation
The 'c' in argv stands for argument count, which represents the number of arguments passed to the program. The 'v' stands for argument vector, which refers to an array of strings that contains the actual arguments passed to the program.
19.
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 length of command-line arguments can vary depending on the operating system. Different operating systems may have different limits on the maximum combined length of command-line arguments. Therefore, the maximum combined length of command-line arguments including the spaces between adjacent arguments may vary from one operating system to another.
20.
What is the output of this C code?#include main(){if (sizeof(int) > -1)printf("True");elseprintf("False");}
Correct Answer
D. False
Explanation
The code compares the size of the integer data type with the value -1. Since the size of the integer is always a positive value, the condition sizeof(int) > -1 will always evaluate to true. Therefore, the code will print "True". However, the given answer is "False", which contradicts the explanation. Therefore, the correct answer cannot be determined based on the given information.
21.
What will be the output of the following program?
#include
#define square(x) x*x
void main()
{
int i;
i = 64/square(4);
printf("%d", i);
}
Correct Answer
B. 64
Explanation
The program defines a macro `square(x)` which calculates the square of a number. In the main function, the variable `i` is assigned the value of 64 divided by the square of 4, which is 64/16. Therefore, the value of `i` is 4. However, the program does not have a `printf` statement to print the value of `i`, so the output of the program will be nothing.
22.
What will happen after compiling and running following code?main(){printf("%p", main);}
Correct Answer
B. Will make an infinite loop
Explanation
The code will not make an infinite loop. Instead, it will print the address of the main function. The code uses the printf function to print the address of the main function, which is represented by the format specifier "%p". Therefore, the correct answer is "Some address will be printed".
23.
Any C program
Correct Answer
A. Must contain at least one function.
Explanation
In the C programming language, a program must contain at least one function. A function is a block of code that performs a specific task, and it is the basic building block of a C program. Without a function, the program would not have any executable code and would not be able to perform any actions. Therefore, it is necessary for a C program to have at least one function in order to be valid and functional.
24.
Determine output:
main()
{
int i = abc(10);
printf("%d", --i);
}
int abc(int i)
{
return(i++);
}
Correct Answer
B. 9
Explanation
The output of the code will be 9. In the main function, the variable i is assigned the value returned by the abc function, which is 10. Then, the value of i is decremented by 1 using the pre-decrement operator (--i). Since the pre-decrement operator is used, the value of i will be decremented before it is printed using the printf function. Therefore, the output will be 9.
25.
Determine Output:
void main()
{
static int var = 5;
printf("%d ", var--);
if(var)
main();
}
Correct Answer
B. 5 4 3 2 1
Explanation
The program starts by initializing a static variable "var" to 5. Then it prints the value of "var" (5) and decrements it by 1. It then checks if "var" is non-zero, which it is, so it calls the main function recursively. This process continues until "var" becomes 0. Each time the main function is called recursively, it prints the value of "var" and decrements it. Therefore, the output will be 5 4 3 2 1.
26.
Determine the Final Output:
void main()
{
printf("\nab");
printf("\bsi");
printf("\rha");
}
Correct Answer
D. Hai
Explanation
The given code snippet is written in C programming language.
The first line of code `printf("ab");` prints the string "ab" to the console.
The second line of code `printf("\bsi");` uses the backspace escape sequence (\b) to move the cursor back one position, effectively erasing the last character 'b' from the previous line. It then prints the string "si" to the console.
The third line of code `printf("\rha");` uses the carriage return escape sequence (\r) to move the cursor to the beginning of the line. It then prints the string "ha" to the console, overwriting the previous content.
Therefore, the final output is "hai".
27.
Let x be an array. Which of the following operations are illegal?
Correct Answer
D. X*2
Explanation
The given question asks which of the operations are illegal on an array "x". The operation "x*2" is illegal because you cannot multiply an array by a scalar value. Arrays are not directly compatible with arithmetic operations like multiplication.
28.
Determine output:void main(){int i=10;i = !i>14;printf("i=%d", i);}
Correct Answer
D. 0
Explanation
The given code snippet assigns the value of 10 to the variable 'i'. Then, it checks if the logical NOT of 'i' (which is 10) is greater than 14. Since this condition is false, the value assigned to 'i' becomes 0. Finally, the code prints the value of 'i', which is 0.
29.
What will be output if you will compile and execute the following c code?
void main(){
int i=4,x;
x=++i+++i+++i;
printf("%d",x);
}
Correct Answer
A. 21
Explanation
The code uses the pre-increment operator (++i) multiple times on the same variable (i) in the same expression. According to the operator precedence rules, the rightmost ++i is evaluated first, incrementing i to 5. Then, the next ++i is evaluated, incrementing i to 6. Finally, the leftmost ++i is evaluated, incrementing i to 7. The value of i is then added three times (7+7+7) and assigned to x, resulting in x=21. Therefore, the output of the code will be 21.
30.
What will be output if you will compile and execute the following c code?
void main(){
char *str="Hello world";
printf("%d",printf("%s",str));
}
Correct Answer
D. Hello world11
Explanation
The code initializes a pointer variable `str` to point to the string "Hello world". The `printf` function is used to print the string `str`, which returns the number of characters printed. This return value is then printed using `printf` again. So, the output will be "Hello world" followed by the number of characters in the string, which is 11.