- -32767 to 32768
- -32668 to 32667
- -32768 to 32767
Explanation: In a 16-bit C compiler, we have 2 bytes to store the value.
- The range for signed integers is -32768 to 32767.
- The range for unsigned integers is 0 to 65535.
- The range for unsigned character is 0 to 255.
2) Study the following program:
main()
{printf("logic practice");
main();}
What will be the output of this program?
- Wrong statement
- It will keep on printing logic practice
- It will Print logic practice once
- None of the these
In this code snippet, the primary function recursively invokes itself, resulting in a continuous output of "logic practice".
3) What is required in each C program?
- The program must have at least one function.
- The program does not require any function.
- Input data
- Output data
(a) The software should include a minimum of one function.
Explanation: Each C program includes at least one function, and even the simplest programs can define extra functions. A function functions as a block of code, essentially acting as a sub-program.
4) What will this program print?
main()
{
int i = 2;
{
int i = 4, j = 5;
printf("%d %d", i, j);
}
printf("%d %d", i, j);
}
- 4525
- 2525
- 4545
- None of the these
In this particular program, the sequence of events involves displaying the internal function value initially followed by showcasing the external function value.
5) Which of the following comment is correct when a macro definition includes arguments?
- The opening parenthesis should immediately follow the macro name.
- There should be at least one blank between the macro name and the opening parenthesis.
- There should be only one blank between the macro name and the opening parenthesis.
- All the above comments are correct.
(a) The initial bracket must directly succeed the macro identifier.
Explanation: None
6) What is a lint?
- C compiler
- Interactive debugger
- Analyzing tool
- C interpreter
Explanation: Lint serves as an inspection tool that examines the source code for potentially problematic structures, stylistic flaws, bugs, and identifies programming errors. Lint functions akin to a compiler tool, scanning through the source code files of C programming to validate their syntactic correctness.
7) What is the output of this statement "printf("%d", (a++))"?
- The value of (a + 1)
- The current value of a
- Error message
- Garbage
Explanation: None
8) Study the following program:
main()
{
char x [10], *ptr = x;
scanf ("%s", x);
change(&x[4]);
}
change(char a[])
{
puts(a);
}
- The given input "abcdefg" will result in the following output:
- Randomized letters starting with "a".
Explanation: None
9) Study the following program:
main()
{
int a = 1, b = 2, c = 3:
printf("%d", a + = (a + = 3, 5, a))
}
What will be the output of this program?
Explanation: This is a consequence of the comma operator.
a + = (a + = 3, 5, a)
It initially computes as "a + = 3" meaning a = a + 3, followed by the evaluation of 5, and lastly the evaluation of "a".
Therefore, we will get the output is 4.
Then,
a + = 4
It gives 8 as the output.
10) What does this declaration mean?
int x : 4;
- X is a four-digit integer.
- X cannot be greater than a four-digit integer.
- X is a four-bit integer.
- None of the these
Explanation: This implies that "X" represents a four-bit integer.
11) Why is a macro used in place of a function?
- It reduces execution time.
- It reduces code size.
- It increases execution time.
- It increases code size.
Explanation: A macro is employed instead of a function to minimize code length and enhance efficiency.
12) In the C language, the constant is defined _______.
- Before main
- After main
- Anywhere, but starting on a new line.
- None of the these.
In the C programming language, a constant can be declared at any point within the code, as long as it begins on a fresh line.
How many iterations will the loop below perform?
for(j = 1; j <= 10; j = j-1)
- Forever
- Never
Explanation: None
14) A pointer is a memory address. Suppose the pointer variable has p address 1000, and that p is declared to have type int*, and an int is 4 bytes long. What address is represented by expression p + 2?
- 1002
- 1004
- 1006
- 1008
Explanation: None
What output will be generated when the code below is run with the values a=10, b=5, and c=10?
If ((a > b) && (a <= c))
a = a + 1;
else
c = c+1;
- a = 10, c = 10
- a = 11, c = 10
- a = 10, c = 11
- a = 11, c = 11
Explanation: None
16) Which one of the following is a loop construct that will always be executed once?
- while
- switch
- do while
During a do-while loop, the loop's body is typically executed at least once. After executing the body, the loop evaluates the condition. If the condition is true, the body is executed again; if false, the loop exits.
17) Which of the following best describes the ordering of destructor calls for stack-resident objects in a routine?
- The first object created is the first object destroyed; last created is last destroyed.
- The first object destroyed is the last object destroyed; last created is first destroyed.
- Objects are destroyed in the order they appear in memory, the object with the lowest memory address is destroyed first.
- The order is undefined and may vary from compiler to compiler.
(b) The initial object to be eliminated is the final object removed; the last one created is the first one to be destroyed.
Explanation: None
When declared in this manner, a string can hold a maximum of ```
main
{printf("logic practice");
main;}
char name[20]:
- None of the these
Answer: (b) 20
Explanation: None
19) Directives are translated by the
- Pre-processor
- Compiler
- Linker
- Editor
Answer: (a) Pre-processor
In the C programming language, the preprocessor serves as a macro processor which is dynamically employed by C developers to alter the program prior to its actual compilation (Pre-construction, preprocessor directives are executed).
20) What is the byte size for an "int = D" declaration?
- 2 or 4
Answer: (c) 2 or 4
Explanation: The int type takes 2 or 4 bytes.
21) What feature makes C++ so powerful?
- Easy implementation
- Reusing the old code
- Easy memory management
- All of the above
Answer: (d) All of the above
Explanation: None
22) Which of the following will copy the null-terminated string that is in array src into array dest?
- dest = src;
- dest == src;
- strcpy(dest, src);
- strcpy(src, dest);
Answer: (c) strcpy(dest, src)
The strcpy function is a string operation utilized to duplicate the content from the source to the destination files. The syntax for strcpy is strcpy(destination, source).
23) In the statement "COUT << "logic practice" << end1;", end1 is a ___.
- Extractor
- Inserter
- Manipulator
- Terminator
Answer: (c) Manipulator
Explanation: The End1 I/O manipulator is responsible for adding a newline ('\n') character and then flushing the output stream during printing.
24) Each instance of a class has a different set of
- Class interfaces
- Methods
- Return types
- Attribute values
Answer: (d) Attribute values
Explanation: Every object of the class possesses a unique combination of attribute values.
25) What is the limit on the number of instances that can be instantiated from a class?
- The number of instances can be declared based on the specific needs of the program.
- There is no predefined restriction on the number of instances that can be created.
Answer: (c) As per required
You have the flexibility to instantiate multiple objects of a class as needed. Each object will maintain its unique internal variables, unless they are marked as static, in which case they are shared among all instances.
What value will the variable "num" hold after running the given code?
int num = 58;
num % = 11;
Answer: (a) 3
Explanation: num = 58
num % = 11
num = num % 11
num = 58 % 11
num = 3
The string variable char address line [40] can hold a maximum of 39 characters, as the last character is reserved for the null terminator.
Answer: (b) 39
Explanation: None
What value will the variable num1 hold after running the given set of instructions?
int j = 1, num1 = 4;
while (++j <= 10)
{
num1++;
}
Answer: (c) 13
Explanation: None
What will be the value of the len variable after running the provided code snippet?
int len;
char str1 = {"39 march road"};
len = strlen(str1);
Answer: (c) 13
Explanation: Strlen is a string function that calculates the length of a string, including both characters and spaces. For example, the string "(39 march road)" has a length of 13 characters.
30) Study the following statement
include <stdio.h>
int main
{
int *ptr, a = 10;
ptr = &a;
*ptr += 1;
printf("%d,%d/n", *ptr, a);
}
What will be the output?
- 10, 10
- 10, 11
- 11, 10
- 11, 11
Answer: (d) 11, 11
Explanation: None
Based on the provided statement, what content will be shown on the screen?
int * aPtr;
*aPtr = 100;
cout << *aPtr + 2;
Answer: (b) 102
Explanation: aPtr is a pointer to an integer with a value of 100.
= *aPtr + 2
= 100 + 2
= 102
Among the given declarations and assignment statement, which one is equivalent to the expression str[4]?
char str[80];
char * p;
p = str;
- p + 4
- *p + 4
- *(p + 4)
- p [3]
Answer: (c) *(p + 4)
Explanation: None
Which of the following accurately describes the variable balance as declared below?
int ** balance;
- Balance is a point to an integer
- Balance is a pointer to a pointer to an integer
- Balance is a pointer to a pointer to a pointer to an integer
- Balance is an array of integer
Answer: (b) Balance is a reference to a pointer pointing to an integer
Explanation: This code description indicates that the remainder represents a pointer to a pointer pointing to an integer.
34) A class D is derived from a class B, b is an object of class B, d is an object of class D, and pb is a pointer to class B object. Which of the following assignment statement is not valid?
- d = d;
- b = d;
- d = b;
- *pb = d:
Answer: (c) d = b;
Explanation: Class D inherits from class B, therefore "D" is distinct from B.
35) Which of the following statement is not true?
- A pointer to an int and a pointer to a double are of the same size.
- A pointer musLogic Practice to a data item on the heap (free store).
- A pointer can be reassigned to point to another data item.
- A pointer can point to an array.
(b) A pointer should point to a data item allocated on the heap (free store).
Explanation: None
36) Which of the following SLT template class is a container adaptor class?
- Stack
- List
- Deque
- Vector
Answer: (a) Stack
Explanation: Container Adaptors are a specialized group within Containers that offer various interfaces tailored for sequential containers like stack and queue.
37) What kinds of iterators can be used with vectors?
- Forward iterator
- Bi-directional iterator
- Random access iterator
- All of the above
Answer: (d) All of the above
An iteration functions similarly to a pointer, pointing to a specific element within the container. Various forms of iterations are compatible with vectors.
38) Let p1 be an integer pointer with a current value of 2000. What is the content of p1 after the expression p1++ has been evaluated?
- 2001
- 2002
- 2004
- 2008
Answer: (c) 2004
In computing, the memory allocation for a single pointer integer typically occupies 4 bytes. At present, the numerical value assigned to the variable p1 is 2000.
p1++ = p1 + 1
p1++ = 2004
39) Let p1 and p2 be integer pointers. Which one is a syntactically wrong statement?
- p1 = p1 + p2;
- p1 = p1 - 9;
- p2 = p2 + 9;
- cout << p1 - p2;
Answer: (a) p1 = p1 + p2;
Explanation: None
Suppose that cPtr is a pointer to a character, and its current value is 300. What will be the updated value in cPtr after the subsequent assignment?
cPtr = cPtr + 5;
Answer: (a) 305
Explanation: cPtr = cPtr + 5
cPtr = 300 + 5
cPtr = 305
41) Which is valid expression in c language?
- int my_num = 100,000;
- int my_num = 100000;
- int my num = 1000;
- int my num == 10000;
Answer: (b) int my_num = 100000;
In C language, variable names cannot include special symbols, spaces, or commas.
If addition had higher precedence than multiplication, then the value of the expression (1 + 2 * 3 + 4 * 5) would be different.
Answer: (d) 105
Explanation: (1 + 2 * 3 + 4 * 5)
= (1 + 2) * (3 + 4) * 5
= 3 * 7 * 5
= 105
43) What will be the output of this program?
int main
{
int a=10, b=20;
printf("a=%d b=%d",a,b);
a=a+b;
b=a-b;
a=a-b;
printf("a=%d b=%d",a,b);
return 0;
}
- a = 20, b = 20
- a = 10, b = 20
- a = 20, b = 10
- a = 10, b = 10
Answer: (c) a = 20, b = 10
Explanation: This program is a swapping program.
a = a + b → a = 10 + 20 → a = 30
b = a - b → b = 30 - 20 → B = 10
a = a - b → a = 30 - 10 → a = 20
44) The following statements are about EOF. Which of them is true?
- Its value is defined within stdio.h
- Its value is implementation dependent
- Its value can be negative
- Its value should not equal the integer equivalent of any character
- All of the these
Answer: (e) All of the these
Explanation: All statements are true
45) What does this statement mean?
x - = y + 1;
- x = x - y + 1
- x = -x - y - 1
- x = x + y - 1
- x = x - y - 1
Answer: (d) x = x - y - 1
Explanation: x - = y + 1
x = x - (y + 1)
So, x = x - y - 1
46) Study the following statement
for (i = 3; i < 15; i + = 3)
{printf ("%d", i);
++i;
}
What will be the output?
- 3 6 9 12
- 3 6 9 12 15
- 3 7 11
- 3 7 11 15
Answer: (c) 3 7 15
Explanation: None
47) Study the following statement
main
{
char *s = "Hello,"
"World!";
printf("%s", s);
}
What will be the output?
- Hello, World!
- Hello, World!
- Hello
- Compile error
Answer: (b) Hello, World!
The program results in displaying "Hello, World!". The absence of the \n escape sequence in the code prevents the output from appearing on a new line.
48) Study the following array definition
int num[10] = {3, 3, 3};
Which of the following statement is correct?
- num[9] is the last element of the array num
- The value of num[8] is 3
- The value of num[3] is 3
- None of the above
(a) The element num[9] represents the final item within the num array.
Explanation: The element num[9] represents the final item in the number array. Given that this array contains a total of 10 elements and is zero-indexed, the last element is accessed using num[9].
What is the expected output after running the provided code?
main
{
printf ("\\n ab");
printf ("\\b si");
printf ("\\r ha");
}
- absiha
- asiha
- haasi
Answer: (d) hai
Explanation:
- \\n - newline - printf("\\nab"); - Prints 'ab'
- \\b - backspace - printf("\\bsi"); - firstly '\\b' removes 'b' from 'ab ' and then prints 'si'. So, after execution of printf("\\bsi"); it is 'asi'
- \\r - linefeed - printf("\\rha"); - Now here '\\r' moves the cursor to the start of the current line and then override 'asi' to 'hai'
After running the given code, what will be the resulting output?
void main
{
int i = 065, j = 65;
printf ("%d %d", i, j);
}
- 065 65
- 53 65
- 65 65
- Syntax error
Answer: (b) 53 65
Explanation: This value (065) represents an octal value, which is equivalent to the decimal value 53.