# C Pointers Test 1

## 1) In a structure, if a variable works as a pointer then from the given below operators which operator is used for accessing data of the structure using the variable pointer?

1. %
2. ->
3. .
4. #

The correct option is (b).

Explanation:

For a structure, Arrow ( ->) is used for access the data using pointer variable and Dot(.) operator can be used for accessing the data using normal structure variable.

## 2) For the array element a[i][j][k], determine the equivalent pointer expression.

1. *(*(*(*(a+i)+j)+k)+2)
2. *( ((a+m)+n+o+p)
3. ((((a+m)+n)+o)+p)
4. *( (((a+m)+n)+o+p)

The correct option is (a).

Explanation:

For the array element a[i][j] the pointer expression is *(*(a+i)+j)

For the array element a[i][j][k] the pointer expression is *(*(*(a+i)+j)+k)

For the array element a[i][j][k] the pointer expression is *(*(*(*(a+i)+j)+k)+2)

## 3) Are the expression ++*ptr and *ptr++ are same?

1. True
2. False

The correct option is (b).

Explanation:

++*ptr increments the value pointed by ptr and*ptr++ increments the pointer not the value.

## 4) Select the correct statement which is a combination of these two statements,

1. char *p = (char*)malloc(100);
2. char *p = (char) malloc(100);
3. char p = *malloc(100);
4. None of the above

The correct option is (a).

Explanation:

The below code is a prototype of malloc() function, here ptr indicates the pointer.

In below code, "*p" is a pointer of data type char and malloc() function is used for allocating the memory for char.

## 5) For the below mention C statement, what is your comment?

1. Would throw Runtime error
2. Improper typecasting
3. Memory will be allocated but cannot hold an int value in the memory
4. No problem with the statement

The correct option is (d).

Explanation:

The size of int and unsigned data type is same therefore there is no problem in a C statement:

signed int *p=(int*)malloc(sizeof(unsigned int));   