int (*func_ptr)(int, int, int);
Which of the following function signatures can be correctly assigned to func_ptr?
func_ptr must point to a function that takes exactly 3 int parameters and returns int. Only option A matches this signature exactly.
#include
int main() {
int a = 5, b = 10;
a = a ^ b;
b = a ^ b;
a = a ^ b;
printf("%d %d", a, b);
return 0;
}
This is a classic XOR swap algorithm. After three XOR operations, a and b exchange their values. Result: a=10, b=5.
#include
int main() {
int arr[5] = {1, 2, 3, 4, 5};
int *p = arr;
printf("%d %d", *(p+2), arr[2]);
return 0;
}
*(p+2) accesses the element at index 2 (value 3), and arr[2] also accesses index 2 (value 3). Both print 3.
int x = 5;
int *ptr = &x;
int **pptr = &ptr;
printf("%d", **pptr);
What is the output?
pptr is a pointer to pointer. **pptr dereferences twice: first to get ptr, then to get x's value which is 5.
Variable names cannot start with a digit. They must start with a letter or underscore. Option B violates this rule.
#include
int main() {
char str[] = "GATE";
printf("%d", sizeof(str));
return 0;
}
sizeof(str) includes the null terminator. The string "GATE" has 4 characters plus 1 null terminator = 5 bytes.
memcpy(dest, src, count) copies 'count' bytes from src to dest. strlen() and sizeof() may not give correct results for all data types.
5/2 is integer division (not float division), so result is 2 (integer), then converted to 2.0 (float).
int (*func)(); declares a pointer to a function that returns int. Option A declares a function returning pointer to int.
Initial: a=1, b=2. After step 1: a=3, b=2. After step 2: a=3, b=1. After step 3: a=2, b=1. Output is '2 1'.