0% found this document useful (0 votes)
20 views

C++ Assignments - Pointers - Week 4

Uploaded by

ans78hu
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
20 views

C++ Assignments - Pointers - Week 4

Uploaded by

ans78hu
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

C++ Assignments | Pointers | Week 4

Q1 : Write a program to find the product of two numbers using pointers.

Q2 : int *p, q;

p is a pointer and q is an integer.


p and q both are pointers.
P and q both are integers.
Syntax is incorrect.

Q3: Find the output of the following code snippet.

int a = 10, b = 20;


int *ptr = &a;
b = *ptr + 1;
ptr = &b;
cout << *ptr << ‘ ‘ << a << ‘ ‘ << b;

11 11 10
10 10 10
11 10 11
10 11 10

Q4: Find the output of the following code snippet.

int a = 15, b = 20;


int *ptr = &a;
int *ptr2 = &b;
*ptr = *ptr2;

ptr now points to b


ptr2 now points to a
a gets value of b
b gets value of a

Q5: Is the following program snippet correct?


int a = 10, b = 20;
int *ptr;
*ptr = 5;

Note:- Please try to invest time doing the assignments which are necessary to build a strong foundation.
Do not directly Copy Paste using Google or ChatGPT. Please use your brain .

You might also like