0% found this document useful (0 votes)
47 views6 pages

Quiz About C Pointer Basics

The document contains a series of programming questions related to C pointers, including code snippets and multiple-choice answers. Each question tests knowledge on pointer behavior, memory management, and output predictions in C programming. The document is designed for practice and discussion among learners.

Uploaded by

chandra
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
47 views6 pages

Quiz About C Pointer Basics

The document contains a series of programming questions related to C pointers, including code snippets and multiple-choice answers. Each question tests knowledge on pointer behavior, memory management, and output predictions in C programming. The document is designed for practice and discussion among learners.

Uploaded by

chandra
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

Tutorials

Search... Sign In
Practice
Jobs
DSA Practice Problems C C++ Java Python JavaScript Data Science Machine Learning Courses Linux DevOps SQL Web Develop

C Pointer Basics
Last Updated : Mar 19, 2024 Discuss

Question 1

What is the output of following program?

# include <stdio.h>
void fun(int x)
{
x = 30;
}

int main()
{
int y = 20;
fun(y);
printf("%d", y);
return 0;
}

A 30

B 20

C Compiler Error

D Runtime Error

Discuss it

Question 2

Output of following program?

# include <stdio.h>
void fun(int *ptr)
{
*ptr = 30;
}

int main()
{
int y = 20;
fun(&y);
printf("%d", y);

return 0;
}

A 20

B 30

C Compiler Error
We use cookies to ensure you have the best browsing experience on our website. By using our site, you
Got It !
D acknowledge
Runtime Error that you have read and understood our Cookie Policy & Privacy Policy
Discuss it

Question 3

Output of following program?

#include <stdio.h>

int main()
{
int *ptr;
int x;

ptr = &x;
*ptr = 0;

printf(" x = %d\\n", x);


printf(" *ptr = %d\\n", *ptr);

*ptr += 5;
printf(" x = %d\\n", x);
printf(" *ptr = %d\\n", *ptr);

(*ptr)++;
printf(" x = %d\\n", x);
printf(" *ptr = %d\\n", *ptr);

return 0;
}

x=0
*ptr = 0
A
x=5
*ptr = 5
x=6
*ptr = 6
x = garbage value
*ptr = 0
B
x = garbage value
*ptr = 5
x = garbage value
*ptr = 6
x=0
*ptr = 0
C
x=5
*ptr = 5
x = garbage value
*ptr = garbage value
x=0
*ptr = 0
D
x=0
*ptr = 0
x=0
*ptr = 0

Discuss it

Question 4

Consider a compiler where int takes 4 bytes, char takes 1 byte and pointer takes 4 bytes.

We use cookies
#include to ensure you have the best browsing experience on our website. By using our site, you
<stdio.h>
acknowledge that you have read and understood our Cookie Policy & Privacy Policy
int main()
{
int arri[] = {1, 2 ,3};
int *ptri = arri;

char arrc[] = {1, 2 ,3};


char *ptrc = arrc;

printf("sizeof arri[] = %d ", sizeof(arri));


printf("sizeof ptri = %d ", sizeof(ptri));

printf("sizeof arrc[] = %d ", sizeof(arrc));


printf("sizeof ptrc = %d ", sizeof(ptrc));

return 0;
}

A sizeof arri[] = 3 sizeof ptri = 4 sizeof arrc[] = 3 sizeof ptrc = 4

B sizeof arri[] = 12 sizeof ptri = 4 sizeof arrc[] = 3 sizeof ptrc = 1

C sizeof arri[] = 3 sizeof ptri = 4 sizeof arrc[] = 3 sizeof ptrc = 1

D sizeof arri[] = 12 sizeof ptri = 4 sizeof arrc[] = 3 sizeof ptrc = 4

Discuss it

Question 5

Assume that float takes 4 bytes, predict the output of following program.

#include <stdio.h>

int main()
{
float arr[5] = {12.5, 10.0, 13.5, 90.5, 0.5};
float *ptr1 = &arr[0];
float *ptr2 = ptr1 + 3;

printf("%f ", *ptr2);


printf("%d", ptr2 - ptr1);

return 0;
}

A 90.500000 3

B 90.500000 12

C 10.000000 12

D 0.500000 3

Discuss it

Question 6

#include<stdio.h>
int main()
{
We use cookies
int arr[]to ensure
= {10,you20,
have30,
the best
40, browsing
50, 60};experience on our website. By using our site, you
intacknowledge
*ptr1 = arr;that you have read and understood our Cookie Policy & Privacy Policy
int *ptr2 = arr + 5;
printf("Number of elements between two pointer are: %d.",
(ptr2 - ptr1));
printf("Number of bytes between two pointers are: %d",
(char*)ptr2 - (char*) ptr1);
return 0;
}

Assume that an int variable takes 4 bytes and a char variable takes 1 byte

A Number of elements between two pointer are: 5. Number of bytes between two pointers are: 20

B Number of elements between two pointer are: 20. Number of bytes between two pointers are: 20

C Number of elements between two pointer are: 5. Number of bytes between two pointers are: 5

D Compiler Error

E Runtime Error

Discuss it

Question 7

#include<stdio.h>
int main()
{
int a;
char *x;
x = (char *) &a;
a = 512;
x[0] = 1;
x[1] = 2;
printf("%d\\n",a);
return 0;
}

What is the output of above program?

A Machine dependent

B 513

C 258

D Compiler Error

Discuss it

Question 8

int main()
{
char *ptr = "GeeksQuiz";
printf("%c", *&*&*ptr);
return 0;
}

We use cookies to ensure you have the best browsing experience on our website. By using our site, you
acknowledge that you have read and understood our Cookie Policy & Privacy Policy
A Compiler Error

B Garbage Value

C Runtime Error

D G

Discuss it

Question 9

#include<stdio.h>
void fun(int arr[])
{
int i;
int arr_size = sizeof(arr)/sizeof(arr[0]);
for (i = 0; i < arr_size; i++)
printf("%d ", arr[i]);
}

int main()
{
int i;
int arr[4] = {10, 20 ,30, 40};
fun(arr);
return 0;
}

A 10 20 30 40

B Machine Dependent

C 10 20

D Northing

Discuss it

Question 10

The reason for using pointers in a C program is

A Pointers allow different functions to share and modify their local variables.

B To pass large structures so that complete copy of the structure can be avoided.

C Pointers enable complex “linked" data structures like linked lists and binary trees.

D All of the above

Discuss it

We use cookies to ensure you have the best browsing experience on our website. By using our site, you
Tags: C Quiz
acknowledge that you have read and understood our Cookie Policy & Privacy Policy
There are 43 questions to complete.

Take a part in the ongoing discussion View All Discussion

Company Explore Tutorials DSA Data Science & Web


About Us Job-A-Thon Python Data Structures ML Technologies
Corporate & Communications Legal Offline Java Algorithms Data Science With HTML
Address: Privacy Policy Classroom C++ DSA for Python CSS
Careers Program PHP Beginners
A-143, 7th Floor, Machine Learning JavaScript
Sovereign Corporate In Media DSA in GoLang Basic DSA ML Maths TypeScript
Tower, Sector- 136, Noida, Contact Us JAVA/C++ SQL Problems Data Visualisation ReactJS
Uttar Pradesh (201305) Corporate Master R Language DSA Roadmap Pandas NextJS
Solution System Android DSA Interview
Registered Address: NumPy NodeJs
Campus Design Questions
K 061, Tower K, Gulshan NLP Bootstrap
Training Master CP Competitive
Vivante Apartment, Sector Deep Learning Tailwind CSS
137, Noida, Gautam Buddh Program Videos Programming
Nagar, Uttar Pradesh,
201305 Python Computer DevOps System School Databases
Tutorial Science Git Design Subjects SQL

Python GATE CS AWS High Level Mathematics MYSQL


Examples Notes Docker Design Physics PostgreSQL

Django Operating Kubernetes Low Level Chemistry PL/SQL

Tutorial Systems Azure Design Biology MongoDB

Python Computer GCP UML Diagrams Social Science

Projects Network DevOps Interview Guide English Grammar


Advertise with us Database Roadmap
Python Design Patterns
Tkinter Management OOAD
Web Scraping System System Design
OpenCV Software Bootcamp
Tutorial Engineering Interview
Python Digital Logic Questions
Interview Design

Question Engineering
Maths

Preparation More Courses Programming Clouds/Devops GATE 2026


Corner Tutorials IBM Languages DevOps GATE CS Rank
Certification C Programming Engineering Booster
Company- Software
Courses with Data AWS Solutions GATE DA Rank
Wise Development
DSA and Structures Architect Booster
Recruitment Software
Placements C++ Certification GATE CS & IT
Process Testing
Web Programming Salesforce Course - 2026
Aptitude Product
Development Course Certified GATE DA
Preparation Management
Data Science Java Administrator Course 2026
Puzzles Project
Programming Programming Course GATE Rank
Company- Management
Languages Course Predictor
Wise Linux
DevOps & Python Full
Preparation Excel
Cloud Course
All Cheat
Sheets

@GeeksforGeeks, Sanchhaya Education Private Limited, All rights reserved

We use cookies to ensure you have the best browsing experience on our website. By using our site, you
acknowledge that you have read and understood our Cookie Policy & Privacy Policy

You might also like