Which operator is used to get the address of a variable in C?
The & operator (address-of operator) returns the memory address of a variable.
What will be the size of a pointer variable on a 64-bit system?
On a 64-bit system, a pointer is 8 bytes (64 bits) regardless of the data type it points to.
What is a NULL pointer?
A NULL pointer is a pointer that points to memory address 0, indicating it doesn't point to any valid memory location.
Which of the following is NOT a valid pointer declaration?
& is a reference operator used in C++, not in C. In C, pointers are declared using *.
Identify the output:
char *str = "Hello";
printf("%c", *str);
*str dereferences the pointer to get the first character of the string, which is 'H'.
Advertisement
A pointer variable stores the _____ of another variable.
Pointers store memory addresses of variables. The address-of operator (&) retrieves this address.
What is the size of a pointer variable on a 32-bit system?
On a 32-bit system, all pointers are 4 bytes (32 bits) regardless of the data type they point to.
Consider: int x = 10; int *p = &x; What does the expression *p represent?
The dereference operator (*) accesses the value at the address pointed to by p, which is the value 10.
Which operator is used to get the address of a variable?
The & (address-of) operator returns the memory address of a variable.
What will be printed by the code: char *ptr = "Hello"; printf("%c", *ptr);
ptr points to the first character of the string, so *ptr dereferences to 'H'. The %c format specifier prints a single character.
What is the size of a pointer variable in a 64-bit system?
In a 64-bit system, all pointers occupy 8 bytes regardless of the data type they point to.
What does the & operator do when used with a variable?
The & (address-of) operator returns the memory address of the variable.
What is the output of the following code?
int x = 20;
int *p = &x;
printf("%d", *p);
The * operator dereferences the pointer p, accessing the value it points to, which is 20.
Which of the following is a void pointer?
void* is a generic pointer that can hold addresses of any data type and requires explicit typecasting when used.
What is the output of the following code?
int x = 5;
int *p = &x;
int q = &p;
printf("%d", q);
q is a pointer to pointer p. **q dereferences p twice, giving the value of x which is 5.
What will be the size of the pointer variable on a 64-bit system?
int *ptr;
On a 64-bit system, all pointers are 8 bytes regardless of the data type they point to.
What is the output?
int arr[] = {10, 20, 30};
int *p = arr;
printf("%d %d", *(p+1), arr[1]);
p+1 points to second element (20). arr[1] is also 20. Both print the same value.
What does void *ptr represent?
void* is a generic pointer. It can be cast to any other pointer type. No arithmetic can be done directly.
What is the output?
void swap(int *a, int *b) {
int temp = *a;
*a = *b;
*b = temp;
}
int x = 5, y = 10;
swap(&x, &y);
printf("%d %d", x, y);
swap() exchanges values through pointers. x becomes 10, y becomes 5 after function call.
What is the output?
char str[] = "ABC";
char *p = str;
printf("%c", *(p+2));
p+2 points to str[2] which is 'C'. Note: str[3] is null terminator.