C Pointers Test Quiz

Explanation:

For data access in a structure, the Arrow (->) symbol is employed with pointer variables, while the Dot (.) operator is utilized with regular structure variables.

2) For the array element aik, determine the equivalenLogic Practiceer expression.

  • ((((a+i)+j)+k)+2)
  • *( ((a+m)+n+o+p)
  • ((((a+m)+n)+o)+p)
  • *( (((a+m)+n)+o+p)

Explanation:

For the array element ai, the pointer expression can be represented as ((a+i)+j).

For the array element ai[k], the pointer expression would be ((*(a+i)+j)+k).

For the array item aik, the pointer expression would be ((((a+i)+j)+k)+2).

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

  • True
  • False

Explanation:

Incrementing the value pointed to by the pointer using ++ptr, and incrementing the pointer itself, not the value it points to, using ptr++.

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

Example

Statement 1: p= (char*) malloc(100);

Statement 2: char *p;
  • char p = (char)malloc(100);
  • char *p = (char) malloc(100);
  • char p = *malloc(100);
  • None of the above

Explanation:

The following code snippet serves as a prototype for the malloc function, where ptr is a pointer.

Example

ptr = (data type *)malloc(size);

In the following code snippet, "*p" represents a char data type pointer, and the malloc function is employed to reserve memory space for a char data type.

Example

char *p = (char*)malloc(100);

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

Example

signed int *p=(int*)malloc(sizeof(unsigned int));
  • Would throw Runtime error
  • Improper typecasting
  • Memory will be allocated but cannot hold an int value in the memory
  • No problem with the statement

Explanation:

The integer and unsigned data types are of equal size, so there is no issue with a C statement that utilizes both types.

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

Input Required

This code uses input(). Please provide values below: