Example HTML page

Assignment 17 : Pointers MCQ

Hi,

Practice the following Questions.

1.What is the output of the following code.

#include <stdio.h>
int main()
{
  int var = 10;
  printf("Value: %d\n", var);
  printf("Address: %u", &var);  
  return 0;
}
Example 1

2. What is the output of the following program. reason.

# include <stdio.h>
void method1(int var)
{
    var = 30;
}
 
int main()
{
  int z= 20;
  method1(z);
  printf("%d", z);
  return 0;
}

3. What is the output of the following code.

# include <stdio.h>
void method1(int *ptr)
{
    *ptr = 30;
}
 
int main()
{
  int z = 20;
  method1(&z);
  printf("%d", z);
 
  return 0;
}

4. What is the output of the following code.

#include <stdio.h>
 
int main()
{
    int *ptr;
    int y;
 
    ptr = &y;
    *ptr = 0;
 
    printf(" y = %d \n", y);
    printf(" *ptr = %d \n", *ptr);
 
    *ptr += 5;
    printf(" y  = %d \n", y);
    printf(" *ptr = %d \n", *ptr);
 
    (*ptr)++;
    printf(" y = %d \n", y);
    printf(" *ptr = %d \n", *ptr);
 
    return 0;
}

5. What is the output of the following code.

#include<stdio.h>
int main()
{
 char *ptr = "Sudhakar";
 printf("%c \n", *&*&*ptr);
 return 0;
}

6. What is the output of the following code.

#include <stdio.h>
void method1(int *p)
    {
        int j = 2;
        p = &j;
        printf("%d ", *p);
    }
    int main()
    {
        int i = 100, *p = &i;
        method1(&i);
        printf("%d ", *p);
    }
    

7. What is the output of the following code.

#include<stdio.h>
int main()
{
char *p = NULL;
char *q = 0;
if (p)
printf("Hello \n");
else
printf("null Hello \n");
if (q)
printf("Sudhakar \n");
else
printf("null Sudhakar\n");
}

8. What is the output of the following code.

#include<stdio.h>
int main()
{
int i = 10;
void *p = &i;
printf("%d\n", (int)*p);
return 0;
}

9. What is the output of the following code. is it give any error?

#include<stdio.h>

int main()
{
    int *x;
    *x=100;
    return 0;
}

10. Pointer variable is declared using ___ sign.

a. *      b. &     c. ^    d. $

 

Thank You for visiting our blog.

 

 

 

 

Example HTML page

Leave a Reply

Your email address will not be published. Required fields are marked *

Pin It on Pinterest