1.
What is the output of the below code snippet?#include<stdio.h> main(){ int a = 5, b = 3, c = 4; printf("a = %d, b = %d\n", a, b, c);}
Correct Answer
A. a=5, b=3
Explanation
The code snippet will output "a = 5, b = 3". This is because the printf statement is printing the values of variables 'a' and 'b' using the format specifier "%d". The values of 'a' and 'b' are 5 and 3 respectively. The variable 'c' is not being printed in the printf statement, so its value does not affect the output.
2.
What is the output of the following program?#include<stdio.h> main(){ struct { int x;} var = {5}, *p = &var; printf("%d %d %d",var.x,p->x,(*p).x);}
Correct Answer
A. 5 5 5
Explanation
The program defines a structure variable named "var" with an integer member "x" and initializes it to 5. It also declares a pointer variable "p" of the same structure type and assigns the address of "var" to it.
The printf statement prints the value of "var.x", "p->x", and "(*p).x". Since "var.x" is 5, "p->x" and "(*p).x" both access the value of "x" through the pointer "p", which points to "var". Therefore, all three values are 5.
3.
What is the built in library function to adjust the allocated dynamic memory size.
Correct Answer
C. Realloc
Explanation
The correct answer is "realloc". The realloc function is a built-in library function in C that is used to adjust the size of dynamically allocated memory. It allows for the reallocation of memory blocks, either expanding or reducing their size. This function is particularly useful when the size of the memory needed by a program changes during its execution. By using realloc, the program can efficiently manage memory allocation and deallocation, optimizing the use of resources.
4.
What is the output of the following program?#include<stdio.h>main(){ fprintf(stdout,"Hello, World!");}
Correct Answer
A. Hello, world!
Explanation
The program uses the fprintf function to print the string "Hello, World!" to the standard output stream (stdout). Therefore, the output of the program will be "Hello, world!".
5.
A Variable name in C includes which special symbols?
Correct Answer
D. _ (underscore)
Explanation
In C, a variable name can include the underscore symbol (_). This symbol is often used to separate words within a variable name to improve readability. For example, a variable name like "first_name" is more descriptive than "firstname". The other special symbols listed, such as asterisk, hash, and addition, are not allowed in variable names in C.
6.
The correct order of mathematical operators in mathematics and computer programming,
Correct Answer
B. Division, Multiplication, Addition, Subtraction
Explanation
In mathematics and computer programming, the correct order of mathematical operators is known as the order of operations. This order dictates that division should be done before multiplication, and multiplication should be done before addition and subtraction. This is because division and multiplication have higher precedence than addition and subtraction. Therefore, the correct order of mathematical operators is Division, Multiplication, Addition, Subtraction.
7.
Choose the correct order of evaluation,
Correct Answer
B. Arithmetic Relational Logical Assignment
Explanation
The correct order of evaluation is Arithmetic Relational Logical Assignment. This means that arithmetic operations are performed first, followed by relational operations, then logical operations, and finally assignment operations. This order ensures that calculations are performed correctly and logical conditions are evaluated in the appropriate sequence.
8.
What is the output of the below code snippet?#include<stdio.h> main(){ for(;;)printf("Hello");}
Correct Answer
A. Infinite loop
Explanation
The code snippet contains an infinite loop because there are no conditions specified in the for loop. The loop will continue to execute indefinitely, repeatedly printing "Hello" without any interruption or termination.
9.
Compiler generates ___ file.
Correct Answer
B. Object code
Explanation
A compiler generates object code files. Object code is the output of the compilation process, where the source code is translated into a lower-level representation that can be directly executed by the computer's hardware or combined with other object code files to create an executable program. Object code is specific to the target architecture and can be further processed by a linker to generate the final executable code. Assembly code is a human-readable representation of the machine code and is generated by an assembler, not a compiler. Therefore, the correct answer is object code.
10.
C is the successor of ___ programming language.
Correct Answer
C. B
Explanation
C++ is the successor of the C programming language. C++ was developed as an extension of the C language, adding object-oriented programming features and other enhancements. B++ and MINI C are not programming languages, and B is not the successor of the C language.
11.
Which library function can convert an integer/long to a string?
Correct Answer
A. ltoa()
Explanation
The ltoa() function is used to convert a long integer to a string. This function takes the long integer as input and converts it into a string representation. Therefore, ltoa() is the correct library function to convert an integer/long to a string.
12.
What is the output of the following program?#include<stdio.h>void f(){ static int i = 3; printf("%d ", i); if(--i) f();}main(){ f();}
Correct Answer
B. 3 2 1
Explanation
The program defines a function f() that has a static variable i initialized to 3. The function prints the value of i and then recursively calls itself with i decremented by 1. This process continues until i becomes 0. So, the output of the program will be 3 2 1.
13.
Identify the incorrect file opening mode from the following.
Correct Answer
C. X
Explanation
The incorrect file opening mode is "x". The file opening modes "r", "w", and "a" are valid modes in Python. "r" is used for reading a file, "w" is used for writing to a file (and overwriting the existing content), and "a" is used for appending content to a file. However, "x" is not a valid file opening mode in Python.
14.
In C, what are the various types of real data type (floating point data type)?
Correct Answer
C. Float, double, long double
Explanation
The correct answer is float, double, long double. In the C programming language, the various types of real data types or floating point data types are float, which is used to store single-precision floating point numbers, double, which is used to store double-precision floating point numbers, and long double, which is used to store extended-precision floating point numbers. These data types are used to represent numbers with fractional parts or numbers that are too large or too small to be represented using integer data types.
15.
To print a double value which format specifier can be used?
Correct Answer
B. %If
Explanation
The correct answer is "%If". This format specifier is used to print a double value in C programming language. The "%" symbol is used to indicate a format specifier, and "f" is used to specify that the value is a double. Therefore, "%If" is the correct format specifier to print a double value.
16.
What is the output of the following program?#include<stdio.h>void main(){ char s[ ] = "C++"; printf("%s ",s); s++; printf("%s",s);}
Correct Answer
D. Compile error
Explanation
The program will give a compile error because the line "s++;" is trying to increment the array name 's', which is not allowed in C++. Array names are constant pointers and cannot be modified.
17.
Which of the following statement shows the correct implementation of nested conditional operation by finding greatest number out of three numbers?
Correct Answer
A. Max = a>b ? a>c?a:c:b>c?b:c
Explanation
The correct implementation of nested conditional operation to find the greatest number out of three numbers is shown in the answer "max = a>b ? a>c?a:c:b>c?b:c". This statement uses nested ternary operators to compare the numbers and determine the maximum value. The first ternary operator compares a and b, and if a is greater, it compares a with c to determine the maximum. If b is greater, it compares b with c to determine the maximum. This way, the statement finds the greatest number among a, b, and c.
18.
Specify the 2 library functions to dynamically allocate memory?
Correct Answer
C. Malloc() and calloc()
Explanation
The correct answer is malloc() and calloc(). These are two library functions used to dynamically allocate memory in C programming. malloc() is used to allocate a block of memory of a specified size, while calloc() is used to allocate and initialize a block of memory for an array of elements. Both functions are commonly used in C programming for dynamic memory allocation.
19.
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 an array is passed as an argument to a function in C, only the base address of the array is actually passed. This means that the memory address of the first element of the array is passed to the function. By using this base address, the function can access and manipulate the elements of the array.
20.
Which of the following function is used to find the first occurrence of a given string in another string?
Correct Answer
C. Strstr()
Explanation
The strstr() function is used to find the first occurrence of a given string within another string. It searches for the first instance of the specified substring and returns a pointer to the location within the original string where the substring is found.