Pointer
Name: _____________________
Date: _____________________
Instructions: Answer all questions. Write your answers clearly in the space provided.
In linux, argv[0] by command-line argument can be occupied by . . . . . . . .
An array of similar data types which themselves are a collection of dissimilar data type are . . . . . . . .
In C, what is a pointer primarily used for?
What is the result of the expression sizeof(int*) in C, assuming an int pointer on a typical system?
What is the purpose of the '->' operator in C when used with pointers?
In C, what is the value of a pointer variable if it hasn't been assigned any address?
What is the result of the expression *ptr in C, where ptr is a pointer to an int?
In C, what is the purpose of the 'void' pointer type (void*)?
What is the result of the expression ptr++ in C, where ptr is a pointer?
In C, what is the purpose of the 'const' keyword when used with a pointer declaration?
Which of the following statements are true? P. Pointer to Array
Q. Multi-dimensional array
Which of the following is not possible statically in C?
Which of the following can never be sent by call-by-value?
A program that has no command line arguments will have argc . . . . . . . .
What is argv[0] in command line arguments?
Which is an indirection operator among the following?
One of the uses for function pointers in C is . . . . . . . .
What is the index of the last argument in command line arguments?
What is the maximum number of arguments that can be passed in a single function?
Arguments that take input by user before running a program are called?
What is the advantage of a multidimensional array over pointer array?
What is the base data type of a pointer variable by which the memory would be allocated to it?
What is the result of the expression ptr-- in C, where ptr is a pointer?
In C, what is a function pointer?
What is the result of the expression &array[0] in C, where array is an integer array?
In C, what is a null pointer (NULL or 0)?
What is the result of the expression ptr += 2 in C, where ptr is a pointer?
In C, what is the purpose of the 'calloc' function?
What is the result of the expression *ptr = 42 in C, where ptr is a pointer to an int?
What is the result of the expression *ptr = NULL in C, where ptr is a pointer?
In C, what is a pointer to a constant pointer (int* const)?
How to call a function without using the function name to send parameters?
Comment on an array of the void data type.
What is the syntax for constant pointer to address (i.e., fixed pointer address)?
Which of the following is not possible in C?
How many number of pointer (*) does C have against a pointer variable declaration?
Which type of variables can have the same name in a different function?
What does argc and argv indicate in command-line arguments? (Assuming: int main(int argc, char *argv[]) )
What are the applications of a multidimensional array?
Choose the best answer. Prior to using a pointer variable
The address operator & , cannot act on
The operator > and < are meaningful when used with pointers, if
What is the result of the expression &variable in C, where variable is a variable of type int?
In C, what is a double pointer (int**)?
What is the result of the expression ptr = NULL in C, where ptr is a pointer?
In C, what is the purpose of the 'malloc' function?
What is the result of the expression *NULL in C?
In C, what is the purpose of the 'memcpy' function?
What is the result of the expression sizeof(char*) in C, assuming a char pointer on a typical system?
In C, what is a pointer to a constant value (const int*)?
What type of array is generally generated in Command-line argument?
Which of the following is a correct syntax to pass a Function Pointer as an argument?
Calling a function f with a an array variable a[3] where a is an array, is equivalent to . . . . . . . .
In C, how do you declare an array of pointers to integers?
What is the purpose of the 'free' function in C when used with pointers?
What will be the output of the following C code? #include <stdio.h>
int main()
{
char *str = "hello, world
"
str[5] = '.'
printf("%s
", str)
return 0
}
Is the below declaration legal? int* ((*x)())[2]
What will be the output of the following C code? #include <stdio.h>
void main()
{
int a[2][3] = {1, 2, 3, , 4, 5}
int i = 0, j = 0
for (i = 0
i < 2
i++)
for (j = 0
j < 3
j++)
printf("%d", a[i][j])
}
What will be the output of the following C code (run without any command line arguments)? #include <stdio.h>
int main(int argc, char *argv[])
{
while (*argv++ != NULL)
printf("%s
", *argv)
return 0
}
What will be the output of the following C code? #include <stdio.h>
void main()
{
char s[] = "hello"
s++
printf("%c
", *s)
}
What will be the output of the following C code? #include <stdio.h>
int main()
{
int i = 11
int *p = &i
foo(&p)
printf("%d ", *p)
}
void foo(int *const *p)
{
int j = 10
*p = &j
printf("%d ", **p)
}
What will be the output of the following C code? #include <stdio.h>
void main()
{
int k = 5
int *p = &k
int **m = &p
printf("%d%d%d
", k, *p, **p)
}
What will be the output of the following C code? #include <stdio.h>
void main()
{
int x = 0
int *ptr = &5
printf("%p
", ptr)
}
What will be the output of the following C code? #include <stdio.h>
int main()
{
char *str = "hello, world
"
char *strc = "good morning
"
strcpy(strc, str)
printf("%s
", strc)
return 0
}
What will be the output of the following C code? #include <stdio.h>
void main()
{
char *s = "hello"
char *p = s
printf("%c %c", *p, s[1])
}
What is the correct way to declare and assign a function pointer? (Assuming the function to be assigned is "int multi(int, int)
")
What will be the output of the following C code? #include <stdio.h>
struct student
{
int no = 5
char name[20]
}
void main()
{
struct student s
s.no = 8
printf("hello")
}
What will be the output of the following C code? #include <stdio.h>
void f(int (*x)(int))
int myfoo(int i)
int (*foo)(int) = myfoo
int main()
{
f(foo(10))
}
void f(int (*i)(int))
{
i(11)
}
int myfoo(int i)
{
printf("%d
", i)
return i
}
What will be the output of the following C code? #include <stdio.h>
void fun(char *k)
{
printf("%s", k)
}
void main()
{
char s[] = "hello"
fun(s)
}
What will be the output of the following C code? #include <stdio.h>
int main()
{
int i = 0, j = 1
int *a[] = {&i, &j}
printf("%d", *a[0])
return 0
}
What will be the output of the following C code? #include <stdio.h>
int main()
{
int *ptr, a = 10
ptr = &a
*ptr += 1
printf("%d,%d/n", *ptr, a)
}
What will be the output of the following C code? #include <stdio.h>
int *f()
int main()
{
int *p = f()
printf("%d
", *p)
}
int *f()
{
int *j = (int*)malloc(sizeof(int))
*j = 10
return j
}
Comment on the following two operations. int *a[] = {{1, 2, 3}, {1, 2, 3, 4}}
//- 1
int b[][] = {{1, 2, 3}, {1, 2, 3, 4}}
//- 2
What will be the output of the following C code? #include <stdio.h>
void main()
{
char *s = "hello"
char *p = s
printf("%c %c", *(p + 1), s[1])
}
Which of the following does not initialize ptr to null (assuming variable declaration of a as int a=0
)?
What will be the output of the following C code? #include <stdio.h>
int main()
{
double *ptr = (double *)100
ptr = ptr + 2
printf("%u", ptr)
}
What type of initialization is needed for the segment "ptr[3] = '3'
" to work?
What will be the output of the following C code? #include <stdio.h>
void main()
{
int k = 5
int *p = &k
int **m = &p
printf("%d%d%d
", k, *p, **m)
}
What will be the output of the following C code? #include <stdio.h>
void main()
{
struct student
{
int no
char name[20]
}
struct student s
s.no = 8
printf("%s", s.name)
}
What will be the output of the following C code? #include <stdio.h>
int main()
{
int ary[4] = {1, 2, 3, 4}
int *p = ary + 3
printf("%d %d
", p[-2], ary[*p])
}
What will be the output of the following C code? #include <stdio.h>
void m(int p, int q)
{
printf("%d %d
", p, q)
}
void main()
{
int a = 6, b = 5
m(a)
}
What will be the output of the following C code? #include <stdio.h>
void f(int (*x)(int))
int myfoo(int)
int (*fooptr)(int)
int ((*foo(int)))(int)
int main()
{
fooptr = foo(0)
fooptr(10)
}
int ((*foo(int i)))(int)
{
return myfoo
}
int myfoo(int i)
{
printf("%d
", i + 1)
}
In C, what is a pointer to a function that takes no arguments and returns an integer?
What will be the output of the following C code? #include <stdio.h>
int main()
{
int i = 10
void *p = &i
printf("%d
", (int)*p)
return 0
}
What will be the output of the following C code? #include <stdio.h>
void main()
{
char *a[10] = {"hi", "hello", "how"}
int i = 0
for (i = 0
i < 10
i++)
printf("%s", *(a[i]))
}
What will be the output of the following C code? #include <stdio.h>
int main()
{
const int ary[4] = {1, 2, 3, 4}
int *p
p = ary + 3
*p = 5
printf("%d
", ary[3])
}
What will be the output of the following C code? #include <stdio.h>
void foo( int[] )
int main()
{
int ary[4] = {1, 2, 3, 4}
foo(ary)
printf("%d ", ary[0])
}
void foo(int p[4])
{
int i = 10
p = &i
printf("%d ", p[0])
}
What will be the output of the following C code? #include <stdio.h>
void main()
{
int a[3] = {1, 2, 3}
int *p = a
printf("%p %p", p, a)
}
What will be the output of the following C code (run without any command line arguments)? #include <stdio.h>
int main(int argc, char *argv[])
{
while (*argv != NULL)
printf("%s
", *(argv++))
return 0
}
What will be the output of the following C code? #include <stdio.h>
void m(int *p)
{
int i = 0
for(i = 0
i < 5
i++)
printf("%d ", p[i])
}
void main()
{
int a[5] = {6, 5, 3}
m(&a)
}
What will be the output of the following C code (if run with no options or arguments)? #include <stdio.h>
int main(int argc, char *argv[])
{
printf("%d
", argc)
return 0
}
Comment on the following C statement. const int *ptr
What will be the output of the following C code? #include <stdio.h>
void main()
{
char a[10][5] = {"hi", "hello", "fellows"}
printf("%p
", a)
printf("%p", a[0])
}
What will be the output of the following C code on a 32-bit system? #include <stdio.h>
void main()
{
char *a[10] = {"hi", "hello", "how"}
printf("%d
", sizeof(a[1]))
}
What will be the output of the following C code? #include <stdio.h>
void f(int a[2][])
{
a[0][1] = 3
int i = 0, j = 0
for (i = 0
i < 2
i++)
for (j = 0
j < 3
j++)
printf("%d", a[i][j])
}
void main()
{
int a[2][3] = {0}
f(a)
}
What will be the output of the following C code? #include <stdio.h>
int mul(int a, int b, int c)
{
return a * b * c
}
void main()
{
int *function_pointer
function_pointer = mul
printf("The product of three numbers is:%d",
function_pointer(2, 3, 4))
}
What will be the output of the following C code? #include <stdio.h>
int main()
{
int ary[4] = {1, 2, 3, 4}
int *p = ary + 3
printf("%d
", p[-2])
}
What will be the output of the following C code? #include <stdio.h>
int x = 0
void main()
{
int *ptr = &x
printf("%p
", ptr)
x++
printf("%p
", ptr)
}
What will be the output of the following C code? #include <stdio.h>
struct student
{
int no = 5
char name[20]
}
void main()
{
struct student s
s.no = 8
printf("hello")
}
Which is true for a, if a is defined as "int a[10][20]
"?
Which of the following expression is true for the following C statement? ptr is array with 3 elements of pointer to function returning pointer of int
What will be the output of the following C code? #include <stdio.h>
int main()
{
char a[2][6] = {"hello", "hi"}
printf("%d", sizeof(a))
return 0
}
What will be the output of the following C code? #include <stdio.h>
int main()
{
int a[4] = {1, 2, 3, 4}
void *p = &a[1]
void *ptr = &a[2]
int n = 1
n = ptr - p
printf("%d
", n)
}
What will be the output of the following C code? #include <stdio.h>
void main()
{
int x = 0
int *ptr = &x
printf("%p
", ptr)
ptr++
printf("%p
", ptr)
}
What is the second argument in command line arguments?
Determine Output: void main()
{
char far *farther, *farthest
printf("%d..%d", sizeof(farther), sizeof(farthest))
}
Determine Output: main()
{
char *str1 = "abcd"
char str2[] = "abcd"
printf("%d %d %d", sizeof(str1), sizeof(str2), sizeof("abcd"))
}
Comment on the following pointer declaration? int * ptr, p
What will be the output? main()
{
char *p
p = "Hello"
printf("%cn",*&*p)
}
Determine output: #include <stdio.h>
void main()
{
char *p = NULL
char *q = 0
if(p)
printf(" p ")
else
printf("nullp")
if(q)
printf("q")
else
printf(" nullq")
}
The statement int ** a
What will be the output of the following program? #include<stdio.h>
void main()
{
int i = 10
void *p = &i
printf("%d
", (int)*p)
}
What will be the output of the following program code? #include<stdio.h>
void main()
{
int i = 10
void *p = &i
printf("%f", *(float *)p)
}
The declaration int (* p ) [ 5 ]
means
Comment on the following? const int * ptr
Determine Output: #include<stdio.h>
void main()
{
int *ptr, a=10
ptr = &a
*ptr += 1
printf("%d, %d", *ptr, a)
}
A function 'p' that accepts a pointer to a character as argument and returns a pointer to an array of integer can be declared as
What will be printed after compiling and running the following code? main()
{
char *p
printf("%d %d",sizeof(*p), sizeof(p))
}
What will be the output of the following program code? #include <stdio.h>
void main()
{
int i=3, *j, **k
j = &i
k = &j
printf("%d%d%d", *j, **k, *(*k))
}
Which of the following is the correct way of declaring a float pointer:
Find the output of the following program. void main()
{
char *msg = "hi"
printf(msg)
}
Find the output of the following program. void main()
{
int array[10]
int *i = &array[2], *j = &array[5]
int diff = j-i
printf("%d", diff)
}
What makes the following declaration denote? int **ptr
What will be the output of the following C code? #include <stdio.h>
int main()
{
foo(ary)
}
void foo(int **ary)
{
int i = 10, k = 20, j = 30
int *ary[2]
ary[0] = &i
ary[1] = &j
printf("%d
", ary[0][1])
}
What will be the output of the following C code? #include <stdio.h>
int main()
{
char str[] = "hello, world"
str[5] = '.'
printf("%s
", str)
return 0
}
What will be the output of the following C code? #include <stdio.h>
int main()
{
int i = 10
int *const p = &i
foo(&p)
printf("%d
", *p)
}
void foo(int **p)
{
int j = 11
*p = &j
printf("%d
", **p)
}
Which of the following arithmetic operation can be applied to pointers a and b? (Assuming initialization as int *a = (int *)2
int *b = (int *)3
)
What will be the output of the following C code? #include <stdio.h>
void main()
{
char a[10][5] = {"hi", "hello", "fellows"}
printf("%d", sizeof(a[1]))
}
Comment on the following two operations. int *a[] = {{1, 2, 3}, {1, 2, 3, 4}}
//- 1
int b[4][4] = {{1, 2, 3}, {1, 2, 3, 4}}
//- 2
Which function is not called in the following C program? #include <stdio.h>
void first()
{
printf("first")
}
void second()
{
first()
}
void third()
{
second()
}
void main()
{
void (*ptr)()
ptr = third
ptr()
}
Which of the following syntax is correct for command-line arguments?
What will be the output of the following C code? #include <stdio.h>
void f(char *k)
{
k++
k[2] = 'm'
printf("%c
", *k)
}
void main()
{
char s[] = "hello"
f(s)
}
What will be the output of the following C code? #include <stdio.h>
void f(int)
void (*foo)(float) = f
int main()
{
foo(10)
}
void f(int i)
{
printf("%d
", i)
}
Which of the following is the correct syntax to declare a 3 dimensional array using pointers?
What will be the output of the following C code? #include <stdio.h>
void main()
{
char *s = "hello"
char *n = "cjn"
char *p = s + n
printf("%c %c", *p, s[1])
}
What will be the output of the following C code? #include <stdio.h>
int mul(int a, int b, int c)
{
return a * b * c
}
void main()
{
int (*function_pointer)(int, int, int)
function_pointer = mul
printf("The product of three numbers is:%d",
function_pointer(2, 3, 4))
}
Comment on the output of the following C code. #include <stdio.h>
int main()
{
char *str = "This" //Line 1
char *ptr = "Program
"
//Line 2
str = ptr
//Line 3
printf("%s, %s
", str, ptr)
//Line 4
}
What will be the output of the following C code? #include <stdio.h>
int main()
{
char *a = {"p", "r", "o", "g", "r", "a", "m"}
printf("%s", a)
}
What will be the output of the following C code (run without any command line arguments)? #include <stdio.h>
int main(int argc, char *argv[])
{
while (argv != NULL)
printf("%s
", *(argv++))
return 0
}
Read the following expression? void (*ptr)(int)
What will be the output of the following C code? #include <stdio.h>
void main()
{
int a[3] = {1, 2, 3}
int *p = a
int **r = &p
printf("%p %p", *r, a)
}
What is the first argument in command line arguments?
What will be the output of the following C code? #include <stdio.h>
int main()
{
int i = 0, j = 1
int *a[] = {&i, &j}
printf("%d", (*a)[1])
return 0
}
Which of the following is the correct syntax to send an array as a parameter to function?
Which is true for b, if b is defined as "int *b[10]
"?
Comment on the output of the following C code. #include <stdio.h>
int main()
{
int a = 10
int **c -= &&a
}
What will be the output of the following C code? #include <stdio.h>
int main()
{
int ary[2][3]
ary[][] = {{1, 2, 3}, {4, 5, 6}}
printf("%d
", ary[1][0])
}
What makes the following declaration denote? char *str[5]
What will be the output of the following C code? #include <stdio.h>
void foo(int *ary[])
int main()
{
int ary[2][3]
foo(ary)
}
void foo(int *ary[])
{
int i = 10, j = 2, k
ary[0] = &i
ary[1] = &j
*ary[0] = 2
for (k = 0
k < 2
k++)
printf("%d
", *ary[k])
}
What will be the output of the following C code? #include <stdio.h>
void main()
{
int a[3] = {1, 2, 3}
int *p = a
int *r = &p
printf("%d", (**r))
}
What will be the output of the following C code? #include <stdio.h>
struct student
{
int no
char name[20]
}
void main()
{
struct student s
s.no = 8
printf("hello")
}
Which of the following declaration is illegal?
What will be the output of the following C code? #include <stdio.h>
int mul(int a, int b, int c)
{
return a * b * c
}
void main()
{
int (function_pointer)(int, int, int)
function_pointer = mul
printf("The product of three numbers is:%d",
function_pointer(2, 3, 4))
}
What will be the output of the following C code? #include <stdio.h>
void main()
{
int x = 0
int *ptr = &x
printf("%d
", *ptr)
}
What will be the output of the following C code? #include <stdio.h>
int main()
{
int ary[4] = {1, 2, 3, 4}
int p[4]
p = ary
printf("%d
", p[1])
}
What will be the output of the following C code? #include <stdio.h>
int main()
{
int *((*x)())[2]
x()
printf("after x
")
}
int *((*x)())[2]
{
int **str
str = (int*)malloc(sizeof(int)* 2)
return str
}
What will be the output of the following C code? #include <stdio.h>
void main()
{
int k = 5
int *p = &k
int **m = &p
**m = 6
printf("%d
", k)
}
What will be the output of the following C code? #include <stdio.h>
int *f()
int main()
{
int *p = f()
printf("%d
", *p)
}
int *f()
{
int j = 10
return &j
}
What will be the output of the following C code? #include <stdio.h>
struct student
{
int no
char name[20]
}
void main()
{
student s
s.name = "hello"
printf("hello")
}
Which of the following are generated from char pointer?
Which of the following declaration will result in run-time error?
What will be the output of the following C code? #include <stdio.h>
int main()
{
char *a[2] = {"hello", "hi"}
printf("%s", *(a + 1))
return 0
}
What will be the output of the following C code? #include <stdio.h>
int main()
{
char *p = NULL
char *q = 0
if (p)
printf(" p ")
else
printf("nullp")
if (q)
printf("q
")
else
printf(" nullq
")
}
What will be the output of the following C code? #include <stdio.h>
int main()
{
int i = 97, *p = &i
foo(&i)
printf("%d ", *p)
}
void foo(int *p)
{
int j = 2
p = &j
printf("%d ", *p)
}
What will be the output of the following C code? #include <stdio.h>
int main()
{
int ary[2][3][4], j = 20
ary[0][0] = &j
printf("%d
", *ary[0][0])
}
What will be the output of the following C code? #include <stdio.h>
void m(int *p, int *q)
{
int temp = *p
*p = *q
*q = temp
}
void main()
{
int a = 6, b = 5
m(&a, &b)
printf("%d %d
", a, b)
}
What will be the output of the following C code? #include <stdio.h>
int main()
{
int i = 97, *p = &i
foo(&p)
printf("%d ", *p)
return 0
}
void foo(int **p)
{
int j = 2
*p = &j
printf("%d ", **p)
}
What will be the output of the following C code? #include <stdio.h>
int main()
{
void *p
int a[4] = {1, 2, 3, 8}
p = &a[3]
int *ptr = &a[2]
int n = p - ptr
printf("%d
", n)
}
What will be the output of the following C code? #include <stdio.h>
void main()
{
char *s= "hello"
char *p = s
printf("%c %c", 1[p], s[1])
}
What will be the output of the following C code? #include <stdio.h>
void main()
{
int a[2][3] = {1, 2, 3, 4, 5}
int i = 0, j = 0
for (i = 0
i < 2
i++)
for (j = 0
j < 3
j++)
printf("%d", a[i][j])
}
What will be the output of the following C statement? (assuming the input is "cool brother in city") printf(“%s
”, argv[argc])
What will be the output of the following C code? #include <stdio.h>
int main()
{
char a[2][6] = {"hello", "hi"}
printf("%s", *a + 1)
return 0
}
What will be the output of the following C code? #include <stdio.h>
int main()
{
char *str = "hello world"
char strc[] = "good morning india
"
strcpy(strc, str)
printf("%s
", strc)
return 0
}
What will be the output of the following C code? #include <stdio.h>
void m(int p)
{
printf("%d
", p)
}
void main()
{
int a = 6, b = 5
m(a, b)
printf("%d %d
", a, b)
}
What will be the output of the following C code on a 32-bit system? #include <stdio.h>
void main()
{
char *a[10] = {"hi", "hello", "how"}
printf("%d
", sizeof(a))
}
What will be the output of the following C code? #include <stdio.h>
int sub(int a, int b, int c)
{
return a - b - c
}
void main()
{
int (*function_pointer)(int, int, int)
function_pointer = ⊂
printf("The difference of three numbers is:%d",
(*function_pointer)(2, 3, 4))
}
Find the output of the following program. void main()
{
printf("%d, %d", sizeof(int *), sizeof(int **))
}
Find the output of the following program. void main()
{
int i=10
/* assume address of i is 0x1234ABCD */
int *ip=&i
int **ipp=&&i
printf("%x,%x,%x", &i, ip, *ipp)
}
Which of the following statements are true after execution of the program. void main()
{
int a[10], i, *p
a[0] = 1
a[1] = 2
p = a
(*p)++
}
What would be the output for the following Turbo C code? #include<stdio.h>
void main()
{
int a[]={ 1, 2, 3, 4, 5 }, *p
p=a
++*p
printf("%d ", *p)
p += 2
printf("%d", *p)
}
char* myfunc(char *ptr)
{
ptr+=3
return(ptr)
}
void main()
{
char *x, *y
x = "EXAMVEDA"
y = myfunc(x)
printf("y=%s", y)
} What will be printed when the sample code above is executed?
char *ptr
char myString[] = "abcdefg"
ptr = myString
ptr += 5
what string does ptr point to in the sample code above?
What will be the output of the following C code? #include <stdio.h>
int main()
{
int i = 10
int *p = &i
foo(&p)
printf("%d ", *p)
printf("%d ", *p)
}
void foo(int **const p)
{
int j = 11
*p = &j
printf("%d ", **p)
}
What will be the output of the following C code? #include <stdio.h>
void main()
{
char *s= "hello"
char *p = s
printf("%c %c", *(p + 3), s[1])
}
What will be the output of the following C code? #include <stdio.h>
void main()
{
char *s = "hello"
char *p = s * 3
printf("%c %c", *p, s[1])
}
Which of the following operation is possible using a pointer char? (Assuming the declaration is char *a
)
Comment on the following C statement. int (*a)[7]
What will be the output of the following C code? #include <stdio.h>
int main()
{
int *p = (int *)2
int *q = (int *)3
printf("%d", p + q)
}
What will be the output of the following C code? #include <stdio.h>
void main()
{
char *s= "hello"
char *p = s
printf("%c %c", p[0], s[1])
}
What will be the output of the following C code (run without any command line arguments)? #include <stdio.h>
int main(int argc, char *argv[])
{
while (argc--)
printf("%s
", argv[argc])
return 0
}
What will be the output of the following C code? #include <stdio.h>
int main()
{
int a[4] = {1, 2, 3, 4}
int *p = &a[1]
int *ptr = &a[2]
ptr = ptr * 1
printf("%d
", *ptr)
}
What will be the output of the following C code? #include <stdio.h>
void f(char *k)
{
k++
k[2] = 'm'
}
void main()
{
char s[] = "hello"
f(s)
printf("%c
", *s)
}
What will be the output of the following C code? #include <stdio.h>
void first()
{
printf("Hello World")
}
void main()
{
void *ptr() = first
ptr++
ptr()
}
An array of strings can be initialized by . . . . . . . .
What will be the output of the following C code? #include <stdio.h>
int main()
{
char a[1][5] = {"hello"}
printf("%s", a[0])
return 0
}
What will be the output of the following C code? #include <stdio.h>
void main()
{
char *s = "hello"
char *p = s
printf("%p %p", p, s)
}
What will be the output of the following C code? #include <stdio.h>
int main()
{
char *str = "hello world"
char strary[] = "hello world"
printf("%d %d
", strlen(str), strlen(strary))
return 0
}
What will be the output of the following C code? #include <stdio.h>
int main()
{
char *str = "hello, world!!
"
char strc[] = "good morning
"
strcpy(strc, str)
printf("%s
", strc)
return 0
}
What will be the output of the following C code? #include <stdio.h>
int main()
{
void *p
int a[4] = {1, 2, 3, 4}
p = &a[3]
int *ptr = &a[2]
int n = (int*)p - ptr
printf("%d
", n)
}
What is the correct syntax to send a 3-dimensional array as a parameter? (Assuming declaration int a[5][4][3]
)
What will be the output of the following C code? #include <stdio.h>
void f(int a[][])
{
a[0][1] = 3
int i = 0, j = 0
for (i = 0
i < 2
i++)
for (j = 0
j < 3
j++)
printf("%d", a[i][j])
}
void main()
{
int a[2][3] = {0}
f(a)
}
Which of following logical operation can be applied to pointers? (Assuming initialization int *a = 2
int *b = 3
)
What will be the output of the following C code? #include <stdio.h>
void main()
{
int k = 5
int *p = &k
int **m = &p
printf("%d%d%d
", k, *p, **m)
}
What are the different ways to initialize an array with all elements as zero?
What will be the output of the following C code? #include <stdio.h>
int main()
{
int a[4] = {1, 2, 3, 4}
int *ptr = &a[2]
float n = 1
ptr = ptr + n
printf("%d
", *ptr)
}
What is the size of *ptr in a 32-bit machine (Assuming initialization as int *ptr = 10
)?
What will be the output of the following C code? #include <stdio.h>
void f(int (*x)(int))
int myfoo(int)
int (*foo)() = myfoo
int main()
{
f(foo)
}
void f(int(*i)(int ))
{
i(11)
}
int myfoo(int i)
{
printf("%d
", i)
return i
}
Comment on the following 2 arrays with respect to P and Q. int *a1[8]
int *(a2[8])
P. Array of pointers
Q. Pointer to an array
What will be the output of the following C code? #include <stdio.h>
int main()
{
int i = 10
void *p = &i
printf("%f
", *(float*)p)
return 0
}
What will be the output of the following C code? #include <stdio.h>
void main()
{
struct student
{
int no
char name[20]
}
struct student s
no = 8
printf("%d", no)
}
What will be the output of the following C code? #include <stdio.h>
void main()
{
char *a[10] = {"hi", "hello", "how"}
int i = 0
for (i = 0
i < 10
i++)
printf("%s", a[i])
}
What will be the output of the following C code? #include <stdio.h>
void main()
{
char *s= "hello"
char *p = s + 2
printf("%c %c", *p, s[1])
}
What will be the output of the following C code? #include <stdio.h>
void main()
{
int k = 5
int *p = &k
int **m = &p
printf("%d%d%d
", k, *p, **p)
}
What will be the output of the following C code? #include <stdio.h>
void foo(int (*ary)[3])
int main()
{
int ary[2][3]
foo(ary)
}
void foo(int (*ary)[3])
{
int i = 10, j = 2, k
ary[0] = &i
ary[1] = &j
for (k = 0
k < 2
k++)
printf("%d
", *ary[k])
}
What will be the output of the following C code? #include <stdio.h>
int main()
{
char *a[1] = {"hello"}
printf("%s", a[0])
return 0
}
What does this declaration say? int (*(*y)())[2]
What will be the output of the following C code? #include <stdio.h>
int x = 0
void main()
{
int *const ptr = &x
printf("%p
", ptr)
ptr++
printf("%p
", ptr)
}
Comment on the following declaration. int (*ptr)()
// i)
char *ptr[]
// ii)
What will be the output of the following C code (run without any command line arguments)? #include <stdio.h>
int main(int argc, char *argv[])
{
printf("%s
", argv[argc])
return 0
}
What will be the output of the following C code? #include <stdio.h>
void f(int)
void (*foo)(void) = f
int main(int argc, char *argv[])
{
foo(10)
return 0
}
void f(int i)
{
printf("%d
", i)
}
What will be the output of the following C code? #include <stdio.h>
void m(int p, int q)
{
int temp = p
p = q
q = temp
}
void main()
{
int a = 6, b = 5
m(a, b)
printf("%d %d
", a, b)
}
Comment on the following pointer declaration. int *ptr, p
What will be the output of the following C code? #include <stdio.h>
void f(int)
void (*foo)() = f
int main(int argc, char *argv[])
{
foo(10)
return 0
}
void f(int i)
{
printf("%d
", i)
}
What will be the output of the following C code? #include <stdio.h>
void foo(int*)
int main()
{
int i = 10, *p = &i
foo(p++)
}
void foo(int *p)
{
printf("%d
", *p)
}
What will be the output of the following C code? #include <stdio.h>
void (*(f)())(int, float)
typedef void (*(*x)())(int, float)
void foo(int i, float f)
int main()
{
x p = f
p()
}
void (*(f)())(int, float)
{
return foo
}
void foo(int i, float f)
{
printf("%d %f
", i, f)
}
What will be the output of the following C code? #include <stdio.h>
void main()
{
struct student
{
int no
char name[20]
}
struct student s
s.no = 8
printf("%d", s.no)
}
What are the elements present in the array of the following C code? int array[5] = {5}
What will be the output of the following C code? #include <stdio.h>
struct student
{
int no
char name[20]
}
void main()
{
student s
s.no = 8
printf("hello")
}
What will be the output of the following C code? #include <stdio.h>
void foo(float *)
int main()
{
int i = 10, *p = &i
foo(&i)
}
void foo(float *p)
{
printf("%f
", *p)
}
What will be the output of the following C code? #include <stdio.h>
void main()
{
char *a[10] = {"hi", "hello", "how"}
int i = 0, j = 0
a[0] = "hey"
for (i = 0
i < 10
i++)
printf("%s
", a[i])
}
What will be the output of the following C code? #include <stdio.h>
int main()
{
char **p = {"hello", "hi", "bye"}
printf("%s", (p)[0])
return 0
}
What will be the output of the following C code? #include <stdio.h>
struct student
{
int no
char name[20]
}
struct student s
void main()
{
s.no = 8
printf("%s", s.name)
}
What will be the output of the following C code? #include <stdio.h>
int main()
{
int i = 0, j = 1
int *a[] = {&i, &j}
printf("%d", (*a)[0])
return 0
}
What will be the output of the following C code? #include <stdio.h>
int add(int a, int b)
{
return a + b
}
int main()
{
int (*fn_ptr)(int, int)
fn_ptr = add
printf("The sum of two numbers is: %d", (int)fn_ptr(2, 3))
}
What will be the output of the following C code? #include <stdio.h>
void (*(f)())(int, float)
void (*(*x)())(int, float) = f
void ((*y)(int, float))
void foo(int i, float f)
int main()
{
y = x()
y(1, 2)
}
void (*(f)())(int, float)
{
return foo
}
void foo(int i, float f)
{
printf("%d %f
", i, f)
}
What substitution should be made to //-Ref such that ptr1 points to variable c in the following C code? #include <stdio.h>
int main()
{
int a = 1, b = 2, c = 3
int *ptr1 = &a
int **sptr = &ptr1
//-Ref
}
What will be the output of the following C code? #include <stdio.h>
void foo(int*)
int main()
{
int i = 10
foo((&i)++)
}
void foo(int *p)
{
printf("%d
", *p)
}
Which of the following declaration are illegal?
What will be the output of the following C code? #include <stdio.h>
int main()
{
int ary[4] = {1, 2, 3, 4}
printf("%d
", *ary)
}
What will be the output of the following C code? #include <stdio.h>
int main()
{
int a = 1, b = 2, c = 3
int *ptr1 = &a, *ptr2 = &b, *ptr3 = &c
int **sptr = &ptr1 //-Ref
*sptr = ptr2
}
What will be the output of the following C code? #include <stdio.h>
void main()
{
char a[10][5] = {"hi", "hello", "fellows"}
printf("%s", a[2])
}
What will be the output of the following C code (considering sizeof char is 1 and pointer is 4)? #include <stdio.h>
int main()
{
char *a[2] = {"hello", "hi"}
printf("%d", sizeof(a))
return 0
}
What will be the output of the following C code? #include <stdio.h>
int main()
{
char *p[1] = {"hello"}
printf("%s", (p)[0])
return 0
}
What will be the output of the following C code? #include <stdio.h>
int main()
{
char *str = "hello world"
char strary[] = "hello world"
printf("%d %d
", sizeof(str), sizeof(strary))
return 0
}
What will be the output of the following C code? #include <stdio.h>
int main()
{
int a[4] = {1, 2, 3, 4}
int b[4] = {1, 2, 3, 4}
int n = &b[3] - &a[2]
printf("%d
", n)
}
What will be the output of the following C code? #include <stdio.h>
void f(int a[][3])
{
a[0][1] = 3
int i = 0, j = 0
for (i = 0
i < 2
i++)
for (j = 0
j < 3
j++)
printf("%d", a[i][j])
}
void main()
{
int a[2][3] = {0}
f(a)
}
What will be the output of the following C code? #include <stdio.h>
void (*(f)())(int, float)
typedef void (*(*x)())(int, float)
void foo(int i, float f)
int main()
{
x = f
x()
}
void (*(f)())(int, float)
{
return foo
}
void foo(int i, float f)
{
printf("%d %f
", i, f)
}
In C, how do you declare a pointer variable that can store the address of an integer?
How do you declare a pointer to a function that takes two integers and returns an integer in C?
Answer Key
it only releases the memory the pointer points to. Therefore, the correct answer is Option B: Deallocate memory .
{
char far *farther, *farthest
printf("%d..%d", sizeof(farther), sizeof(farthest))
} The sizeof operator is used to determine the size, in bytes, of a variable or data type. 1. ** farther ** and ** farthest ** are both pointers of type **char***. In C, the size of a pointer is typically **4 bytes** on a 32-bit system or **8 bytes** on a 64-bit system. Assuming a standard 32-bit architecture, the size of both pointers would be **4 bytes**.
2. Therefore, the output of the printf function will be:
- sizeof(farther) = 4
- sizeof(farthest) = 4 The printf statement prints these two sizes, resulting in the output **"4..4"**. Hence, the correct answer is **Option C: 4..4**.
ptr is declared as a pointer to an integer because of the `*` symbol next to it. This means that `ptr` can hold the address of an integer variable. p is declared as a regular integer variable, not a pointer. The absence of the `*` symbol means that `p` will hold an integer value directly, not an address. Key Points: - ptr : Pointer to integer, can store addresses of integer variables. - p : Regular integer variable, cannot store addresses.
*ptr += 1
value at address pointing by ptr incremented by 1. As the value at address is changed so variable a also get the updated value.
// p is a pointer to an integer quantity (2) int *p[10]
// p is a 10-element array of pointers to integer quantities (3) int (*p)[10]
// p is a pointer to a 10-element integer array (4) int *p(void)
// p is a function that returns a pointer to an integer quantity (5) int p(char *a)
// p is a function that accepts an argument which is a pointer to a character returns an integer quantity (6) int *p(char *a)
// p is a function that accepts an argument which is a pointer to a character returns a pointer to an integer quantity. (7) int (*p)(char *a)
// p is pointer to a function that accepts an argument which is a pointer to a character returns an integer quantity. (8) int (*p(char *a))[10]
// p is a function that accepts an argument which is a pointer to a character returns a pointer to a 10-element integer array. (9) int p(char (*a)[])
// p is a function that accepts an argument which is a pointer to a character array returns an integer quantity. (10) int p(char *a[])
// p is a function that accepts an argument which is a array of pointers to characters returns an integer quantity (11) int *p(char a[])
// p is a function that accepts an argument which is a character array returns a pointer to an integer quantity (12) int *p(char (*a)[])
// p is a function that accepts an argument which is a pointer to a character array returns a pointer to an integer quantity (13) int *p(char *a[])
// p is a function that accepts an argument which is an array of pointers to characters // returns a pointer to an integer quantity (14) int (*p)(char (*a)[])
// p is pointer to a function that accepts an argument which is a pointer to a character array returns an integer quantity (15) int *(*p)(char (*a)[])
// p is pointer to a function that accepts an argument which is a pointer to a character array returns a pointer to an integer quantity (16) int *(*p)(char *a[])
// p is pointer to a function that accepts an argument which is a array of pointers to characters returns a pointer to an integer quantity (17) int (*p[10])(void)
// p is 10-element array of pointers to functions
each function returns an integer quantity (18) int (*p[10])(char a)
// p is 10-element array of pointers to functions
each function accepts an argument which is a character and returns an integer quantity (19) int *(*p[10])(char a)
// p is 10-element array of pointers to functions
each function accepts an argument which is a character and returns a pointer to an integer quantity (20) int *(*p[10])(char *a)
// p is 10-element array of pointers to functions
each function accepts an argument which is a pointer to a character and returns a pointer to an integer
: Sets the first element of the array 'a' to 1. a[1] = 2
: Sets the second element of the array 'a' to 2. p = a
: Assigns the address of the first element of the array 'a' to the pointer 'p'. (*p)++
: Increments the value at the memory location pointed to by 'p'. Since 'p' points to the first element of 'a', it increments the value of 'a[0]' . After the execution of the program, the value of a[0] will be 2. Therefore, the correct statement is Option B: a[0] = 2 .