1.
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 holds the memory address of a char pointer. It can be used to access or manipulate a sequence of char pointers, such as an array of strings.
2.
Declare the following statement?
"A pointer to an array of three chars".
Correct Answer
D. Char (*ptr)[3];
Explanation
The correct answer is "char (*ptr)[3]". This is because the declaration "char (*ptr)[3]" declares a pointer named "ptr" that points to an array of three characters. The parentheses are used to indicate that ptr is a pointer, and the brackets [3] indicate that the pointer is pointing to an array of three characters.
3.
Which of the following statements are FALSE about the below code?
int main(int ac, char *av[])
{
}
Correct Answer
C. In place of ac and av, argc and argv should be used.
Explanation
The statement "In place of ac and av, argc and argv should be used" is false because ac and av are the conventional names for the arguments in the main function in C programming. argc stands for "argument count" and av stands for "argument vector," which are just alternative names for ac and av respectively.
4.
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 including spaces can vary from one operating system to another. Different operating systems have different limits on the length of command-line arguments. Therefore, the maximum combined length cannot be determined without considering the specific operating system being used.
5.
Which of the following statement is correct prototype of the malloc() function in c ?
Correct Answer
D. Void* malloc(size_t);
Explanation
The correct prototype of the malloc() function in C is void* malloc(size_t). This is because the malloc() function returns a void pointer (void*) which can be cast to any other pointer type. The size_t parameter is used to specify the number of bytes to allocate for the memory block. This allows for dynamic memory allocation in C, where the size of the memory block can vary at runtime.
6.
How many times the while loop will get executed if a short int is 2 byte wide?
#include<stdio.h>
int main()
{
int j=1;
while(j <= 255)
{
printf("%c %d\n", j, j);
j++;
}
return 0;
}
Correct Answer
B. 255 times
Explanation
The while loop will get executed 255 times because the condition in the while loop is "j
7.
What will function gcvt() do?
Correct Answer
A. Convert floating-point number to a string
Explanation
The function gcvt() is used to convert a floating-point number to a string. It takes the floating-point number as input and returns a string representation of that number. This can be useful in situations where we need to display or manipulate the floating-point number as a string, such as in printing or storing the number.
8.
What will be the output of the program?
#include<stdio.h>
int main()
{
int i;
i = scanf("%d %d", &i, &i);
printf("%d\n", i);
return 0;
}
Correct Answer
B. 2
Explanation
The output of the program will be 2. This is because the scanf function is used to read input from the user, and in this case, it is being used to read two integers. The return value of scanf is the number of input items successfully matched and assigned, so in this case, it will be 2. The value of i is not relevant in this case, as it is being overwritten by the scanf function.
9.
What will be the output of the program?
#include<stdio.h>
#include<math.h>
int main()
{
float i = 2.5;
printf("%f, %d", floor(i), ceil(i));
return 0;
}
Correct Answer
C. 2.000000, 0
Explanation
The program uses the floor() and ceil() functions from the math.h library. The floor() function returns the largest integer less than or equal to a given value, while the ceil() function returns the smallest integer greater than or equal to a given value. In this case, the variable i is initialized as 2.5. The floor(i) will return 2, which is the largest integer less than or equal to 2.5. However, the ceil(i) will return 3, which is the smallest integer greater than or equal to 2.5. Therefore, the output of the program will be "2.000000, 0".
10.
What will be the output of the program?
#include<stdio.h>
int main()
{
int i;
i = printf("How r u\n");
i = printf("%d\n", i);
printf("%d\n", i);
return 0;
}
Correct Answer
B. How r u
8
2
Explanation
The program first prints "How r u" and returns the number of characters printed, which is 8. This value is then assigned to the variable i. Then, the program prints the value of i, which is 8. Finally, it prints the value of i again, which is still 8. So, the output of the program is "How r u", followed by two lines of "8".
11.
What will the function randomize() do in Turbo C under DOS?
Correct Answer
C. Returns a random number generator with a random value based on time.
Explanation
The function randomize() in Turbo C under DOS will return a random number generator with a random value based on time. This means that each time the function is called, it will generate a different random value based on the current time. This ensures that the random numbers generated are not predictable and can be used for various purposes such as generating random values in a game or simulation.
12.
Point out the error in the program?
#include<stdio.h>
int main()
{
FILE *fp;
fp=fopen("trial", "r");
fseek(fp, "20", SEEK_SET);
fclose(fp);
return 0;
}
Correct Answer
B. Error: fseek() long offset value
Explanation
The error in the program is that the fseek() function is being passed a string ("20") instead of a long offset value. The fseek() function is used to set the file position indicator for the stream pointed to by the file pointer 'fp'. The third argument of fseek() should be of type long, not a string.
13.
Point out the error in the program?
#include<stdio.h>
int main()
{
char ch;
int i;
scanf("%c", &i);
scanf("%d", &ch);
printf("%c %d", ch, i);
return 0;
}
Correct Answer
B. Error: we may not get input for second scanf() statement
Explanation
The error in the program is that the format specifier in the first scanf() statement is incorrect. The variable 'i' is an int type, but the format specifier used is '%c' which is for char types. This can cause unexpected behavior or errors when trying to read input into 'i'. Additionally, there is a possibility that the second scanf() statement may not receive any input, which can also cause issues when trying to read the value into 'ch'.
14.
To print out a and b given below, which of the following printf() statement will you use?
#include<stdio.h>
float a=3.14;
double b=3.14;
Correct Answer
A. Printf("%f %lf", a, b);
Explanation
The correct answer is printf("%f %lf", a, b) because the format specifier "%f" is used to print a float variable, and the format specifier "%lf" is used to print a double variable. Since "a" is a float and "b" is a double, this printf() statement will correctly print out both variables.
15.
Which of the following operations can be performed on the file "NOTES.TXT" using the below code?
FILE *fp;
fp = fopen("NOTES.TXT", "r+");
Correct Answer
D. Read and Write
Explanation
The code is using the "r+" mode to open the file "NOTES.TXT". This mode allows both reading and writing operations to be performed on the file. Therefore, the correct answer is "Read and Write".
16.
What is the purpose of "rb" in fopen() function used below in the code?
FILE *fp;
fp = fopen("source.txt", "rb");
Correct Answer
A. Open "source.txt" in binary mode for reading
Explanation
The purpose of "rb" in the fopen() function is to open the file "source.txt" in binary mode for reading.
17.
Which of the following statement is correct?
Correct Answer
C. Strcmp(s1, s2) returns 0 if s1==s2
Explanation
The correct answer is that strcmp(s1, s2) returns 0 if s1==s2. This is because strcmp() is a function in C that compares two strings lexicographically. If the two strings are equal, strcmp() returns 0.
18.
Which of the following statements are correct ?
1: A string is a collection of characters terminated by '\0'.
2: The format specifier %s is used to print a string.
3: The length of the string can be obtained by strlen().
4: The pointer CANNOT work on string.
Correct Answer
B. 1, 2, 3
Explanation
Statement 1 is correct because a string in C is represented as a collection of characters terminated by a null character '\0'.
Statement 2 is correct because the format specifier %s is used to print a string in C.
Statement 3 is correct because the strlen() function in C can be used to obtain the length of a string.
Statement 4 is incorrect because pointers can work on strings in C.
19.
If the size of pointer is 32 bits What will be the output of the program ?
#include<stdio.h>
int main()
{
char a[] = "Visual C++";
char *b = "Visual C++";
printf("%d, %d\n", sizeof(a), sizeof(b));
printf("%d, %d", sizeof(*a), sizeof(*b));
return 0;
}
Correct Answer
C. 11, 4
1, 1
Explanation
The size of the array 'a' is 11 because it includes the null character at the end of the string. The size of the pointer 'b' is 4 because it is a 32-bit system and pointers are typically 4 bytes in size. When we use the * operator to dereference the pointers and get the size of the characters they point to, both 'a' and 'b' are of type char, so they have a size of 1 byte. Therefore, the output of the program is "11, 4" and "1, 1".
20.
If char=1, int=4, and float=4 bytes size, What will be the output of the program ?
#include<stdio.h>
int main()
{
char ch = 'A';
printf("%d, %d, %d", sizeof(ch), sizeof('A'), sizeof(3.14f));
return 0;
}
Correct Answer
B. 1, 4, 4
Explanation
The program is using the sizeof() function to determine the size in bytes of different data types. The variable "ch" is of type char and therefore has a size of 1 byte. The character 'A' is also of type char and has a size of 1 byte. The number 3.14f is of type float and has a size of 4 bytes. Therefore, the output of the program will be "1, 4, 4", indicating the size of each data type in bytes.
21.
What will be the output of the program in 16-bit platform (Turbo C under DOS) ?
#include<stdio.h>
int main()
{
printf("%d, %d, %d", sizeof(3.0f), sizeof('3'), sizeof(3.0));
return 0;
}
Correct Answer
B. 4, 2, 8
Explanation
The program uses the sizeof() function to determine the size in bytes of different data types. The first sizeof() function is used on a float value (3.0f), which is a 4-byte data type, so the output is 4. The second sizeof() function is used on a character value ('3'), which is a 1-byte data type, so the output is 1. The third sizeof() function is used on a double value (3.0), which is an 8-byte data type, so the output is 8. Therefore, the output of the program will be 4, 2, 8.
22.
What will be the output of the program ?
#include<stdio.h>
#include<string.h>
int main()
{
static char s[] = "Hello!";
printf("%d\n", *(s+strlen(s)));
return 0;
}
Correct Answer
B. 0
Explanation
The program will output 0. The variable s is a static character array containing the string "Hello!". The expression *(s+strlen(s)) is equivalent to *(s+6), which is the value at the memory location s+6. Since the string "Hello!" has a length of 6, this expression is accessing the memory location just after the null character at the end of the string. In this case, the value at that memory location happens to be 0. So, when we print *(s+strlen(s)), it will print 0.
23.
What will be the output of the program ?
#include<stdio.h>
int main()
{
printf(5+"Good Morning\n");
return 0;
}
Correct Answer
D. Morning
Explanation
The program will output "Morning". This is because the expression "5+"Good Morning" is equivalent to "Good Morning" + 5, which results in the starting address of the string being incremented by 5. Therefore, the program will print the string starting from the 6th character, which is "Morning".
24.
What will be the output of the program ?
#include<stdio.h>
#include<string.h>
int main()
{
printf("%d\n", strlen("123456"));
return 0;
}
Correct Answer
A. 6
Explanation
The program uses the strlen() function to determine the length of the string "123456". Since the string has 6 characters, the output of the program will be 6.
25.
What will be the output of the program ?
#include<stdio.h>
int main()
{
char p[] = "%d\n";
p[1] = 'c';
printf(p, 65);
return 0;
}
Correct Answer
A. A
Explanation
The correct answer is "A".
In the given program, the character array "p" is initialized with the format specifier "%d". Then, the character at index 1 of the array "p" is changed to 'c'.
When the printf function is called with the array "p" as the format string and the integer value 65 as the argument, it will print "65" as the output.
Therefore, the output of the program will be "A".
26.
What will be the output of the program ?
#include<stdio.h>
#include<string.h>
int main()
{
char str1[20] = "Hello", str2[20] = " World";
printf("%s\n", strcpy(str2, strcat(str1, str2)));
return 0;
}
Correct Answer
C. Hello World
Explanation
The program uses the strcpy() and strcat() functions to concatenate the strings str1 and str2. The strcat() function appends str2 to str1, resulting in the string "Hello World". Then, the strcpy() function copies the concatenated string into str2. Therefore, the output of the program is "Hello World".
27.
What will be the output of the program?
#include<stdio.h>
#include<stdlib.h>
int main()
{
int i=0;
i++;
if(i<=5)
{
printf("IndiaBIX");
exit(1);
main();
}
return 0;
}
Correct Answer
D. Prints "IndiaBIx"
Explanation
The program starts by initializing the variable i to 0. Then, it increments i by 1. The program then checks if i is less than or equal to 5. Since i is 1, the condition is true.
Inside the if statement, the program prints "IndiaBIX" and exits with a status of 1. However, before exiting, the program calls the main() function recursively.
This means that the program will continue to execute from the beginning, incrementing i by 1 each time. Since there is no condition to stop the recursion, it will result in an infinite loop.
Therefore, the program will continuously print "IndiaBIX" and will not terminate.
28.
What will be the output of the program?
#include<stdio.h>
int fun(int(*)());
int main()
{
fun(main);
printf("Hi\n");
return 0;
}
int fun(int (*p)())
{
printf("Hello ");
return 0;
}
Correct Answer
C. Hello Hi
Explanation
The program will output "Hello Hi". The function `fun` is called in the `main` function with `main` as an argument. Inside the `fun` function, "Hello " is printed. Then, in the `main` function, "Hi" is printed. Therefore, the output will be "Hello Hi".
29.
What will be the output of the program?
#include<stdio.h>
int fun(int);
int main()
{
float k=3;
fun(k=fun(fun(k)));
printf("%f\n", k);
return 0;
}
int fun(int i)
{
i++;
return i;
}
Correct Answer
A. 5.000000
Explanation
The program defines a function `fun` that takes an integer as input and increments it by 1. In the `main` function, a float variable `k` is initialized with the value 3. The `fun` function is called three times on `k` in a nested manner: `fun(k=fun(fun(k)))`. The innermost call to `fun(k)` increments `k` by 1, making it 4. Then, the next call to `fun` increments 4 by 1, making it 5. Finally, the outermost call to `fun` assigns the value 5 to `k`. Therefore, the output of the program will be 5.000000.
30.
. Point out the error in the program
f(int a, int b)
{
int a;
a = 20;
return a;
}
Correct Answer
C. Redeclaration of a
Explanation
The error in the program is the redeclaration of the variable "a" inside the function. The variable "a" is already declared as a parameter in the function definition, so redeclaring it inside the function is not allowed and causes a compilation error.