1.
Pointer is a special kind of a variable which is used to store _______ of a variable
Correct Answer
D. Address
Explanation
A pointer is a special kind of variable that is used to store the address of another variable. By storing the address, the pointer allows us to indirectly access and manipulate the value of the variable it points to. This is useful in situations where we need to pass variables by reference or dynamically allocate memory. Therefore, the correct answer is "address".
2.
The operator used to declare a pointer variable is
Correct Answer
C. *
Explanation
The correct answer is * because in C and C++, the asterisk (*) symbol is used to declare a pointer variable. The asterisk is placed before the variable name to indicate that it is a pointer variable, which stores the memory address of another variable.
3.
Variable passing by reference is achieved by using pointers.
Correct Answer
A. True
Explanation
Variable passing by reference is achieved by using pointers. In programming, passing by reference means that a reference to the original variable is passed to a function, allowing the function to directly modify the original variable. Pointers are used to achieve this behavior in many programming languages. By passing the memory address of a variable, the function can access and modify the original variable, rather than creating a copy. Therefore, the statement that variable passing by reference is achieved by using pointers is true.
4.
Char data type uses _____ byte (s), int data type uses _____ byte (s) and float uses _____ byte (s)
Correct Answer
C. 1, 2, 4
Explanation
The correct answer is 1, 2, 4. The char data type uses 1 byte, the int data type uses 2 bytes, and the float data type uses 4 bytes.
5.
Passing by value means an exact copy of the variable is created and the value is assigned to it.
Correct Answer
A. True
Explanation
Passing by value means that when a variable is passed as an argument to a function, a copy of the variable is created and the value of the original variable is assigned to it. This means that any changes made to the copy within the function will not affect the original variable. Therefore, the statement is true.
6.
Choose the best answerPrior to using a pointer variable
Correct Answer
C. It should be both declared and initialized
Explanation
Prior to using a pointer variable, it is necessary to both declare and initialize it. Declaring a pointer variable means specifying its data type and name, while initializing it means assigning it a memory address to point to. If a pointer is not declared, it cannot be used in the program. Similarly, if it is not initialized, it does not have a valid memory address to point to, leading to potential errors or undefined behavior when trying to access the memory it points to. Therefore, both declaring and initializing a pointer variable are important steps before using it.
7.
What does the following mean?int *ptr, p;
Correct Answer
A. Ptr is a integer pointer, p is not
Explanation
This statement declares two variables, ptr and p. The declaration "int *ptr" means that ptr is a pointer to an integer. On the other hand, the declaration "p" does not have any asterisk (*) before it, indicating that it is not a pointer. Therefore, the correct answer is that ptr is an integer pointer, while p is not a pointer.
8.
A pointer is
Correct Answer
C. A variable that stores address of other variable
Explanation
A pointer is a variable that stores the address of another variable. Pointers are used to indirectly access and manipulate data stored in memory. By storing the address of a variable, pointers allow for efficient memory management and the ability to pass variables by reference. Therefore, the correct answer is "A variable that stores the address of other variable."
9.
#include<stdio.h>void f(){ printf("hello");}void main(){ f();}the code above has an error.
Correct Answer
B. False
Explanation
The code provided does not have any errors. It includes the necessary header file, defines a function "f()" that prints "hello", and calls the function "f()" in the main function. Therefore, the correct answer is False.
10.
Suppose a variable x has an address fff0. declaring a pointer and assigning address of x is as follow.int *p = &x;printf("address of x = %d", *p);the output will be [address of x = fff0] stored in pointer p?
Correct Answer
B. False
Explanation
The output will not be "[address of x = fff0] stored in pointer p". The output will be the value stored at the address pointed to by pointer p, which is the value of variable x. In this case, it will be the address of x, not the value of x itself.