Important Questions for Class 12 Computer Science (C++) – Pointers

Previous years Examination Questions
2 Marks Questions

Question 1:
Obtain the output from the following C++ program as expected to appear on the screen after its execution. Delhi 2014
Important Note:
All the desired header files are already included in the code, which are required to run the code.

void main()
{
char*String="SARGAM"; 
int *Ptr, A[]={l,5,7,9};
Ptr=A; 
cout<<*Ptr<<String<<endl;
String++;
Ptr+=3;
cout<<*Ptr<<String<<endl;
}

Аnswer:
Output of the given program will be
1SARGAM
9ARGAM

Question 2:
Obtain the output from the following C+ + program as expected to appear on the screen after its execution. All India 2014.2013
Important Note:
All the desired header files are already included in the code, which are required to run the code.

void main()
{
char *Text = "AJANTA"; 
int *P,Num[] = {11,5,7,9};
P = Num;
cout<<*P<<Text<<endl;
Text++;
P++;
cout<<*P<<Text<<endl;
}

Аnswer:
Output of the given program will be
1AJANTA
5JANTA

Question 3:
Observe the following C+ + code carefully and obtain the output, which will appear on the screen after execution of it.
Delhi 2013
Important Note:

All the desired header files are already included in the code, which are required to run the code.

void main()
{
char *String = "SHAKTI"; 
int *Point, Value[]={10,15,70,19};
Point = Value;
cout<<*Point<<String<<endl;
String++;
Point++;
cout<<*Point<<String<<endl;
}

Аnswer:
Output of the given program will be
10SHAKTI
15HAKTI

Question 4:
Give the output of the following program segment: (Assuming, all desired header file(s) are already included). Delhi 2013C

void main()
{
float *Ptr,Points[] = {120,50,30,40,10};
Ptr=Points; 
cout<<*Ptr<<endl;
Ptr+=2;
Points[2]+=2.5; 
cout<<*Ptr<<endl:
Ptr++;
(*Ptr)+=2.5; 
cout<<Points[3]<<endl;
}

Аnswer:
Output of the given program will be
20
32.5
42.5

Question 5:
Find the output of the following program: All India 2012

#include<iostream.h> 
#include<conio.h>
#include<ctype.h> 
typedef char Str80[80]; 
void main() 
{
char *Notes;
Str80 Str="vR.zGooD";
int L=6;
Notes = Str; 
while(L>=3)
{
Str[L]=isupper(Str[L])?
tolower(Str[L]); 
toupper(Str[L]); 
cout<<Notes<<endl;
L--;
Notes++; 
getch();
}
}

Аnswer:
Output of the given program will be
vR.zGoOd
R.zGOOD
.zgOOD
ZgOOD

Question 6:
Find the output of the following program: Delhi 2012

#include<iostream.h> 
#include<conio.h>
#include<ctype.h> 
typedef char Txt80[80]; 
void main()
{
char *PText; 
Txt80 Txt="Ur2GReAt"; 
int N=6;
PText=Txt:
while(N>=3)
{
Txt[N]=isupper(Txt[N])? 
tolower(Txt[N]);
toupper(Txt[N]); 
cout<<PText<<endl;
N--;
PText++;
}
}

Аnswer:
Output of the given program will be
Ur2GReat
r2GREat
2GrEat
grEat

Question 7:
In the following program, what will be the possible output(s) from the following options (i), (ii), (iii) and (iv)? Justify your answer. Delhi 2011C

#include<iostream.h> 
#include<stdlib.h> 
#include<string.h> 
#include<conio.h> 
void main()
{
clrscr();
char *Text="1234"; 
int L=strlen(Text);
randomize(); 
for(int I=0;I<L;I++)
{
int Start=random(I)+1; 
char P=Text[Start]; 
cout<<P<<":";
}
getch();
}
(i) 1:3:2:4: 
(ii) 2:2:3:2:
(iii) 2:2:4:4: 
(iv) 2:2:2:3:

Аnswer:
The possible output will be (ii) 2:2:3:2: and (iv) 2:2:2:3:

Question 8:
Find the output of the following program : Delhi 2011

#include<iostream.h>
#include<conio.h> 
void main()
{
int Track[] = {10, 25, 30, 55},*Striker; 
Striker = Track;
Track[1] += 30;
cout<<"Striker"<<*Striker<<endl; 
*Striker -= 10;
Striker++;
cout<<"Next@"<<*Striker<<endl;
Striker += 2;
cout<<"Last@"<<*Striker<<endl; 
cout<<"Rest To"<<*Striker[0]<<endl;
}

Аnswer:
There is an error in last line, i.e. *Striker[0], so the program will not run. In case, if there is no subscript in Striker pointer, then the output would be
Striker10
Next@55
Last@55
Rest To55

Question 9:
Find the output of the following program: All India 2011

#include<iostream.h> 
#include<conio.h>
void main()
{
int *Queen, Moves[]={11, 22, 33,44};
Queen = Moves;
Moves[2] += 22; 
cout<<"Queen @"<<*Queen<<endl;
*Queen -= 11;
Queen += 2;
cout<<"Now@"<<*Queen<<endl;
Queen++;
cout<<"Finally@"<<*Queen<<endl; 
cout<<"New 0rigin@"<<*Moves[0]<<endl;
}

Аnswer:
There is an error in last line, i.e. *Moves[0], so the program will not run. In case, if there is no subscript in Moves pointer, then the output would be
Queen @11
Now@55
Finally@44
New 0rigin@0

Question 10:
Find the output of the following program:

#include<iostream.h> 
#include<conio.h> 
void main()
{
int Numbers[]={2,4,8,10}; 
int *ptr = Numbers; 
for(int c=0;c<3;c++)
{
cout<<*ptr<<"@";
ptr++;
}
cout<<endl;
for(c=0:c<4:c++)
{
(*ptr) *= 2;
--ptr;
}
for(c=1:c<4;c++)
cout<<Numbers[c]<<"#";
cout<<endl;
}

Аnswer:
Output of the given program will be
2@4@8@
8#16#20#

Question 11:
Find the output of the following program:

#include<iostream.h> 
#include<conio.h> 
void main()
{
int Array[]={4,6,10,12}; 
int *pointer = Array; 
for(int i=1;i<=3;i++)
{
cout<<*pointer<<"#";
pointer++;
}
cout<<endl; 
for(i=1;i<=4;i++)
{
(*pointer) *= 3;
--pointer;
}
for(i=l;i<5;i++)
cout<<Array[i-1]<<"@"; 
cout<<endl;
}

Аnswer:
Output of the given program will be
4#6#10#
12@18@30@36@

Question 12:
Give the output of the following program segment. (Assume, all required header files are included in the program.)

void main()
{
int a=32,*X=&a;
char ch=65, &eco=ch; 
eco+=a;
*X+=ch;
cout<<a<<','<<ch<<endl;
}

Аnswer:
Output of the given program will be
129,a

Question 13:
Identify the syntax error(s), if any, in the following program. Also, give reason for errors.

void main()
{
const int i=20;
const int *const ptr=&i;
(*ptr)++;
int j=15;
ptr=&j;
}

Аnswer:
(*ptr)++ cannot modify a const object ptr-&j cannot modify a const object.

Question 14:
Give the output of the following program segment. (Assume, all required header files are included in the program.)

void main()
{
int array[] = {2,3,4,51}; 
int *arptr=array;
int value=*arptr; 
cout<<va1ue<<'\n'; 
value=*arptr++; 
cout<<value<<'\n'; 
value=*arptr; 
cout<<value<<'\n'; 
value=*++arptr; 
cout<<value<<'\n'; 
}

Аnswer:
Output of the given program will be
2
2
3
4

Question 15:
Give the output of the following program segment. (Assume, all required header files are included in the program.)

void main()
{
char *s="GOODLUCK";
for(int x=strlen(s)-1;x>=0;x--) 
{
for(int y=0;y<=x;y++) 
cout<<s[y]; 
cout<<endl;
}
}

Аnswer:
Output of the given program will be
GOODLUCK
G00DLUC
G00DLU
GOODL
GOOD
GOO
GO
G

Question 16:
Give the output of the following program segment. (Assume, all required header files are included in the program).

void main()
{
char *NAME="a ProFile"; 
for(int x=0;x<strlen(NAME);x++) 
if(islower(NAME[x])); 
else
if(isupper(NAME[x])) 
if(x%2!=0)
NAME[x]=tolower(NAME[x-l] 
else
NAME[x]--;
cout<<NAME<<endl;
}

Аnswer:
Output of the given program will be
a Orooile

Question 17:
Find and write the output of the following C++ program code: All India 2017
NOTE Assume all required header files are already being included in the program.

void main()
{
int *Point, Score[]={100,95,150,75,65,120};
Point=Score; 
for(int L=0;L<6;L++)
{
if((*Point)%10==0) 
*Point /= 2; 
else
*Point -= 2; 
if((*Point)%5==0) 
*Point /= 5; 
Point++;
}
for(int L=5;L>=0;L--)
cout<<Score[L]<<"*";
}

Аnswer:
Given program will give error, i.e. Multiple declaration for ‘L’
If we remove int from 2nd for loop then output will be:
12*63*73*15*93*10*

Question 18:
Find the output of the following program: Delhi 2012C

#include<iostream.h> 
void main() 
{
int Points=300; 
int *Start=&Points; 
int *End;
End=new int;
(*End)=Points-150:
Points+=100;
cout<<Points<<":"<<*Start<<endl; 
cout<<*End<<endl;
Start=End;
cout<<Points<<":"<<*Start<<endl; 
cout<<*End<<endl;
Points-=100;
*Start-=50;
cout<<Points<<":"<<*Start<<endl; 
cout<<*End<<endl; 
delete End;
}

Аnswer:
Output of the given program will be 400:400
150
400:150
150
300:100
100

Question 19:
Find the output of the following program Delhi 2009

#include<iostream.h> 
#include<conio.h> 
void main()
{
int X[]={10, 25, 30, 55, 110}; 
int *p=X; 
whi1e(*p<110)
{
if(*p%3!= 0)
*p = *p+1; 
else
*p = *p+2; 
p++:
}
for(int 1=4;I>=1;I--)
{
cout<<X[I]<<"*"; 
if(I%3 == 0) 
cout<<endl;
} 
cout<<X[0]*3<<endl;
}

Аnswer:
Output of the given program will be
110*56*
32*26*33

Question 20:
Find the output of the following program. Delhi (C) 2009

#include<iostream.h> 
#include<conio.h> 
struct score
{
int Year; 
float topper;
};
void Change(score *s, int x=20)
{
s->topper=(s->topper+25)-x; 
s->Year++;
}
void main()
{
score Arr[]={{2007, 100},{2008, 951}};
score *Point=Arr;
Change(Point, 50); 
cout<<Arr[0].Year<<"#"<<Arr[0].topper<<endl; 
Change(++Point);
cout<<Point->Year<<"#"<<Point->topper<<endl;
}

Аnswer:
Output of the given program will be
2008#75
2009#100

Question 21:
Find the output of the following program. All India 2009

#include<iostream.h>
#include<conio.h> 
void main()
{
int A[] = {10, 15, 20, 25. 30}; 
int *p = A; 
whi1e(*p<30)
{
if(*p%3!= 0)
*p = *p+2;
else
*p = *p+1;
P++;
}
for(int J=0;J<=4;J++)
{
cout<<A[J]<<"*"; 
if(J*3 == 0) 
cout<<endl;
}
cout<<A[4]*3<<endl;
}

Аnswer:
Output of the given program will be
12*
16*22*27*
30*90

Question 22:
What will be the output of the following program?

#include<iostream.h> 
#include<ctype.h>
#include<conio.h>
#include<string.h> 
void ChangeString(char Text[],int SCounter)
{
char *Ptr = Text;
int Length = strlen(Text); 
for(;Counter<Length-2;Counter+=2,Ptr++)
{
*(Ptr+Counter)=toupper(*(Ptr+Counter));
void main()
{
int Position=0;
char Message[]="Pointers Fun"; 
ChangeString(Message, Position); 
cout<<Message<<"@"<<Position;
}

Аnswer:
Output of the given program will be
PoiNteRs Fun@10

Question 23:
What will be the output of the following program?

#include<iostream.h>
#include<ctype.h>
#include<conio.h>
#include<string.h> 
void NewtextCchar String[],int &Position)
{
char *Pointer=String;
int Length=strlen(String);
for(;Position<Length-2;Position+=2,Pointer++)
{
*(Pointer+Position)=toupper(*(Pointer+Position));
}
}
void main()
{
clrscr();
int Location=0;
char Message[]="Dynamic Act";
Newtext(Message, Location);
cout<<Message<<"#"<<Location;
}

Аnswer:
Output of the given program will be
DynAmiC ACt#10

Computer ScienceImportant Questions for Computer ScienceNCERT Solutions