• Skip to main content
  • Skip to primary sidebar
  • Skip to footer
  • NCERT Solutions
    • NCERT Books Free Download
  • TS Grewal
    • TS Grewal Class 12 Accountancy Solutions
    • TS Grewal Class 11 Accountancy Solutions
  • CBSE Sample Papers
  • NCERT Exemplar Problems
  • English Grammar
    • Wordfeud Cheat
  • MCQ Questions

CBSE Tuts

CBSE Maths notes, CBSE physics notes, CBSE chemistry notes

Chapterwise Question Bank CBSE Class 12 Computer Science (C++) – Pointers

Chapterwise Question Bank CBSE Class 12 Computer Science (C++) – Pointers

Exam Practice
Short Answer Type Questions [2/3 Mark]

Question 1:
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
1 AJANTA
5JANTA

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

void main()
{
float *Ptr,Points[]={20,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
20
32.5
42.5

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

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

Аnswer:
Output
Ur2GReat
r2GREat
2GrEat
grEat

Question 4:
Find the output of the following program: Delhi 2009C

#include<iostream.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,95}}; 
Score *Point = Arr; 
change(Point,50);
cout<<Arr[0].Year<<"#"<<Arr[0].topper<<endl;
change(++Point);
cout<<Point->Year<<"#"<<Point->topper<<endl;
}

Аnswer:
Output
2008#75
2009# 100

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

#include<iostream.h> 
void main()
{
int Moves[] = {11, 22, 33, 44},*Queen; 
Queen = Moves;
Moves[2] += 22;
cout<<"Queen @"<<*Queen<<endl;
*Queen -= 11;
Queen += 2;
cout<<"[email protected]"<<*Queen<<endl;
Queen++;
cout<<"[email protected]"<<*Queen<<endl; 
cout<<"New [email protected]"<<*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
[email protected]
[email protected]
New [email protected]

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

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

Аnswer:
Output
110*56*
32*26*33

Question 7:
What will be the output?    All India 2008

#include<iostream.h>
#include<conio.h> 
void main()
{
static int a[]={0,1,2,3,4}; 
int *p[]={a,a+1,a+2,a+3,a+4}; 
int **ptr=p; 
ptr++;
cout<<ptr-p<<" "<<*ptr-a<<" "<<**ptr<<endl;
*ptr++;
cout<<ptr-p<<" "<<*ptr-a<<" "<<**ptr<<endl;
*++ptr;
cout<<ptr-p<<" "<<*ptr-a<<" "<<**ptr<<endl;
++*ptr;
cout<<ptr-p<<" "<<*ptr-a<<" "<<**ptr<<endl;
getch();
}

Аnswer:
Output
1 1 1
2 2 2
3 3 3
4 4 4

Question 8:
Find the output of the following program:

#include<iostream.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
[email protected]@[email protected]
8#16#20#

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

#include<iostream.h>
#include<string.h> 
class state
{
char *state_name; 
int size; 
public: 
state()
{
size = 0;
state_name = new char[size+1];
}
state(char *s)
{
size = strlen(s); 
state_name = new char[size+1]; 
strcpy(state_name,s);
}
void display()
{
cout<<state_name<<endl;
}
void Replace(state &a,state &b)
{
size = a.size + b.size; 
delete state_name; 
state_name = new char[size+1]; 
strcpy(state_name,a.state_name); 
streat(state_name,b.state_name);
}
};
void main() 
{
char *temp = "Delhi"; 
state statel(temp),state2("Mumbai"),state3("Nagpur"),S1,S2;
S1.Replace(state1, state2);
S2.Replace(S1,state3);
S1.display();
S2.display();
}

Аnswer:
There is semicolon(;) after state (char *s ); which will result into syntax error.In case, there is no semicolon(;) after state(char *s),then the output will be:
DelhiMumbai
DelhiMumbaiNagpur

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

#include<iostrearn.h>
#includeCctype.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 Messaged = "Pointers Fun"; 
ChangeString(Message,Position); 
cout<<Message<<"@"<<Position;
}

Аnswer:
Output
PoiQteMs Wun |@10

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

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

Аnswer:
Output
129, a

Question 12:
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:
In the given program, there are two errors:
(*ptr) + + cannot modify const object
ptr = &j cannot modify const object

Question 13:
Give the output of the following program (assume all required header files are include in the program).

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

Аnswer:
Output
2
2
3
4

Question 14:
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
GOODLUCK
GOODLUC
GOODLU
GOODL
GOOD
GOO
GO
G

Question 15:
Give the output of the following program segment (assume all required header files are include 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-1]); 
else
NAME[x]--; 
cout<<NAME<<endl;
}

Аnswer:
a Orooile

Question 16:
Find the output of the following program:

#include<iostream.h>
#include<conio.h> 
void main() 
{
int *PointerArray[10]; 
int marks[]={75,68,90,34,0,10,90,65}; 
for(int I=0;marks[I]!=0;I++)
{
PointerArray[I]=&marks[I]; 
*(PointerArray[I])+=5;
}
int index=0; 
while(index<I)
{
int p=*(PointerArray[index]); 
if(p>60)
cout<<p<<","; 
index++;
}
getch();
}

Аnswer:
Output
80, 73, 95,

Question 17:
A C++ program contains following declaration: static int x[5] =    {5, 20, 30, 50, 70};

  1. What is the meaning of x?
  2. What is the meaning of (x + 2)?
  3. What is the value of *x?
  4. What is the value of (*x + 2)?
  5. What is the value of *(x + 2)?

Аnswer:
Let us assume the base address or the starting address of the array as 1000, i.e
chapterwise-question-bank-cbse-class-12-computer-science-c-pointers-(175-1)
Here, each box is taking 2 bytes because array contains integer type variables and int takes 2 bytes.

  1. x represents an array of size 5 and also the base address of array, i.e. 1000.
  2. It will increase the value of x by 4 bytes, because x + 2 = x + (size of int) *2 = 1000+2*2 =1004
  3. *x means value at the address contained in x[0], i.e. 5.
  4. (*x+ 2)— *(1000)+ 2 [because *(dercfcrcnce operator) has higher priority than binary operators] =5+2=7
  5. *(x+ 2)= *(1000+ 2x 2)= *(1004)= 30

Question 18:
Give the output of the following program:

void main()
{
char *NAME="CoMPutER"; 
for(int x=0;x<strlen(NAME);x++) 
if(islower(NAME[x]))
NAME[x] = toupper(NAME[x]); 
else if(isupper(NAME[x])) 
if(x%2 = 0)
NAME[x] = to!ower(NAME[x]); 
else
NAME[x] = NAME[x-1]; 
puts(NAME);
}

Аnswer:
Output
cOmmUTee

Question 19:
Write the output of the following program:

#include<iostream.h> 
static int i = 100; 
void Print(char *p)
{
p = "Pass";
cout<<"Value is "<<p<<endl;
}
void main()
{
char *q = "Best of Luck";
Print(q);
cout<<"New value is"<<q;
}

Аnswer:
Output
Value is Pass
New value is Best of Luck

Question 20:
Give the output of the following program:

void main()
{
char *Text[2] = {"Two", "six"}; 
for(int C=0;C<2;C++)
{
for(int D=0;D<strlen(Text[0]);D++) 
if(islower(Text[C][D]))
cout<<(char)toupper(Text[C][D]); 
else
if(isupper(Text[C][D])&&(D%2=0)) 
cout<<(char)tolower(Text[C][D]); 
else
cout<<Text[C][D]; 
cout<<D<<endl;
}

Аnswer:
Output
tW03
SIX3

Question 21:
Find syntax error(s), if any, in the following program:

#include<iostream.h> 
main()
{
int x[5],*y,z[5] 
for(i-0;i<5;i++)
{
x[i] = i; 
z[i] = i+3; 
y = z; 
x = y;
}
}

Аnswer:

#incl udeCiostream.h> 
main()
{
int x[5], *y, z[5]  //Errorl 
for(i=0;i<5;i++)  //Error2 
{
x[i]=i; 
z[i]=i+3; 
y=z; 
x=y;
}
}
Error 1 Semicolon missing (;)
Error 2 Declaration syntax error, i is not declared

Computer ScienceChapterwise Question Bank for Computer ScienceNCERT Solutions

Primary Sidebar

NCERT Exemplar problems With Solutions CBSE Previous Year Questions with Solutoins CBSE Sample Papers

Recent Posts

  • ML Aggarwal Class 7 Solutions for ICSE Maths Chapter 16 Perimeter and Area Ex 16.3
  • Paragraph on Madhur Vani in Hindi | मधुर वाणी पर अनुच्छेद लेखन
  • Coordinate Geometry Class 10 Maths CBSE Important Questions With Solutions
  • Sambandh Bodhak in Hindi | संबंधबोधक (Preposition) की परिभाषा एवं उनके भेद और उदाहरण (हिन्दी व्याकरण)
  • NCERT Solutions for Class 7 Maths Chapter 12 Algebraic Expressions InText Questions
  • CBSE Revision Notes for Class 10 English First Flight Chapter 8 Mijbil the Otter
  • Maharashtra Board Class 10 Solutions for Marathi कुमारभारती – कथालेखन
  • NCERT Class 10 Science Lab Manual CO2 is Released During Respiration
  • NCERT Solutions for Class 12 Hindi Core – कार्यालयी हिंदी और रचनात्मक लेखन – कार्यालयी पत्र
  • NCERT Solutions for Class 7 Maths Chapter 13 Exponents and Powers InText Questions
  • NCERT Class 10 Science Lab Manual Dicot Seed
  • NCERT Exemplar Problems Class 7 Maths – Exponents and Powers
  • NCERT Solutions for Class 11 Chemistry Chapter 4 Chemical Bonding and Molecular Structure
  • CBSE Revision Notes for Class 10 English First Flight Chapter 1 A Letter to God
  • NCERT Exemplar Class 10 Maths Solutions Chapter 11 Area Related To Circles

Footer

Maths NCERT Solutions

NCERT Solutions for Class 12 Maths
NCERT Solutions for Class 11 Maths
NCERT Solutions for Class 10 Maths
NCERT Solutions for Class 9 Maths
NCERT Solutions for Class 8 Maths
NCERT Solutions for Class 7 Maths
NCERT Solutions for Class 6 Maths

SCIENCE NCERT SOLUTIONS

NCERT Solutions for Class 12 Physics
NCERT Solutions for Class 12 Chemistry
NCERT Solutions for Class 11 Physics
NCERT Solutions for Class 11 Chemistry
NCERT Solutions for Class 10 Science
NCERT Solutions for Class 9 Science
NCERT Solutions for Class 7 Science
MCQ Questions NCERT Solutions
CBSE Sample Papers
NCERT Exemplar Solutions LCM and GCF Calculator
TS Grewal Accountancy Class 12 Solutions
TS Grewal Accountancy Class 11 Solutions