C Programming Quiz

Quiz for C (Pointers Concepts)

Time left: 300 seconds

Q.1. What does a pointer store?

Select Your Option

A pointer is a variable that stores a memory address. Pointers are used to store the addresses of other variables or memory items. Pointers are very useful for another type of parameter passing, usually referred to as Pass By Address.

Q.2. When declaring a pointer, what is the * operator known as?

Select Your Option

*(asterisk) is used with pointer variable when dereferencing the pointer variable, it refers to variable being pointed, so this is called dereferencing of pointers.Dereferencing is used to access or manipulate data contained in memory location pointed to by a pointer.

Q.3. The * operator is a _____ operator

Select Your Option

'*' is Unary operator that is for indirection or dereferencing operator, when applied to a pointer, it accesses the object the pointer points to.

Q.4. The * operator is also used to get

Select Your Option

Value stored at the address of the variable Explanation : No Explanation

Q.5. The & operator gives

Select Your Option

“ & “ operator in pointer is used to give us the address of the variable.

Q.6. Correct declaration of a pointer variable is:

Select Your Option

The syntax of declaring a pointer is to place a * in front of the name. A pointer is associated with a type (such as int and double) too.

Q.7. The data type of the pointer should be same as the data type of the variable it is pointing to.

Select Your Option

Pointer is a variable which stores the address of that variable to which it is pointing. So the variable to which it is pointing will definitely have a datatype like int, float, char etc. So, a rule states that pointer and the variable to which the pointer is pointing should have the same datatype.

Q.8. Placeholder for pointers in C is

Select Your Option

The %p format specifier is used for printing the value of a pointer in C.

Q.9. Output of the following piece of code is

int main()
{    
	int a=10;
	int *ptr=&a;
	printf("%p\n",ptr);
	printf("%d",*ptr);
	return 0;
}                      


Select Your Option

* operator is used to get the value stored at the address so for *ptr it will show the value at the address and for ptr it will show the address at which the value is stored.

Q.10. What happens when the following statements are executed? int a[5]={10,20,30,40,50}; int *ptr=a; ptr++;

Select Your Option

int *ptr = a; this assigns the first value of array 'a' then for ptr++; it will get the next elements address in the array and point to it.

Q.11. What will be the output of the following code?

#include <stdio.h>
void main()
{
    char *s= "Hello World";
    char *p = s;
    printf("%c %c", *++p, *p++);
}                     


Select Your Option

Q.12. An array name acts like a pointer constant that points to the first element of the array.

Select Your Option

The name of the array acts as a pointer to the first element of the array. int list[10]; the variable list is a pointer to the first integer in the array int *p; p is a pointer. It has the same type as list.

Q.13. If int n[3][2]={{10,20,30},{40,50}}; then, *(n+1)+1 points to?

Select Your Option

n+i point to the element at index i from 1D array now for *(n+i)+j here it will point to element at index i in 1D array and element at index j in 2D array. S0 for n+1 it point to {40,50} and for *(n+1)+1 it points to 50.

Q.14. In call by reference, ____ of the variable is passed

Select Your Option

In call by reference, the address of the variable is passed into the function call as the actual parameter. The value of the actual parameters can be modified by changing the formal parameters since the address of the actual parameters is passed.

Q.15. What will be the output of the following block of code?

void swap(int *p, int *q)
{
	int temp = *p; 
	*p = *q; 
	*q = temp;
}
void main()
{
    int a = 10, b = 20;
    swap(&a, &b);
    printf("%d %d\n", a, b);
}                       


Select Your Option

Inside function swap() we take a local variable temp. Since address of variable a and b are passed to swap() method, we take 2 pointer variables *x and *y. Pointer variable x holds the address of a and pointer variable y holds the address of b. Using below logic we swap the values present at address a( or x ) and b( or y ).

Instructions:-

  1. This Quiz is based on the Pointers concepts of C
  2. Each correct answer will carry 2 points
  3. Once an option is selected you cannot select any other, So choose wisely
  4. Do not refresh the page as it will reset the quiz
  5. Once the time is up the quiz will automatically get submitted with no of Question responded
  6. Your total score alongwith your name will be shown after submission of the Quiz
  7. Wish you ALL THE BEST 👍👍

START

Results:-

Hi




Post a Comment

FOR ANY DOUBTS AND ERRORS FEEL FREE TO ASK. YOUR DOUBTS WILL BE ADDRESSED ASAP

Previous Post Next Post