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

Computer Science Class-Xii (Pointers Assignment) : Cout A++ ++B ++C Endl

The document contains 10 programming questions involving pointers and references in C++. Each question provides sample code and asks the reader to determine the output.

Uploaded by

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

Computer Science Class-Xii (Pointers Assignment) : Cout A++ ++B ++C Endl

The document contains 10 programming questions involving pointers and references in C++. Each question provides sample code and asks the reader to determine the output.

Uploaded by

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

COMPUTER SCIENCE

CLASS-XII (POINTERS ASSIGNMENT)

1) What will be the output of the following program:


#include<iostream.h>
#include<conio.h>
struct Game
{ char Magic[20];
int Score;
};
void main()
{
clrscr();
Game M= {"Tiger", 500};
char *Choice ;
Choice = M.Magic;
Choice [4] =‘P’;
Choice [2] =‘L’;
M.Score+=50;
cout<<M.Magic<<M.Score<<endl;
Game N= M;
N.Score-=120;
cout<<N.Magic<<N.Score<<endl;
getch();
}
2) Give the output of he following program.
#include <iostream.h>
int max(int &x, int &y, int &z)
{ if (x > y && y > z)
{ y++;
z++;
return x;
}
else if (y > x)
return y;
else
return z;
}
void main()
{ int a = 10, b = 13, c = 8;
a = max(a, b, c);
cout << a << b << c << endl;
b = max(a, b, c);
cout << ++a << ++b << ++c << endl;
c = max(a, b, c);
cout << a++ << ++b << ++c << endl;
}
3) Find the output of the program assuming all the required header files have been included :
void main()
{ int x[] = {10, 20, 30, 40,50};
int *p, **q;
int *t;
p = x;
t = x + 1;
q = &t;
cout<<*p<<","<<**q<<","<<*t++;
}

4) Find the output of the following programming code.


void change(char *p, int &loc)
{ for(int i=0; i<loc ; i++ , loc--)
if(islower(*(p+i)))
*(p+i)=*p+i;
else
if(isupper(*(p+i)))
*(p+i)=tolower(*p)+i;
else
*(p+i)='@';
}

void main()
{ char s[ ]="CoMPuTEr FUN";
int len=strlen(s);
cout<<"\n Before change the string is…."<<endl;
cout<<s<<'\t'<<len;
change(s,len);
cout<<"\n After change the string is…"<<endl;
cout<<s<<'\t'<<len;
}
5) Write the output of the following programming code:
char *str="HeLLoWOrLd";
int len=strlen(str)-1;
for(int i=0;i<len-i;i++)
{ str[len]=(isupper(str[len])?tolower(str[len]):toupper(str[len]));
cout<<str<<endl;
str++;
len--;
}
6) Write the output of the following program code:
void getstr(char str[])
{ for (int i = 1; i < strlen (str); i++)
if (isupper (str[i-1]))
str[i-1] = tolower (str[i]);
else
str[i] = toupper (str[i-1]);
}
void main()
{ char s[] = "aNDarIeL";
getstr(s);
cout <<s;
}
7) Write the output of the following program code:
int x = 10;
void pass(int &a, int b, int &c)
{ int x = 4;
c += x;
a *= ::x;
b += c; }
void main()
{ int y = 1, x = 2;
pass(y, ::x, x);
cout << x << ':' << y << ':' << ::x<<endl;
pass(::x, x, y);
cout << x << ':' << y << ':' << ::x;
}

8) Write the output of the following programming code:


void main()
{ int x[]={18,15,29,50,72};
int *y[5];
for(int i=0;i<5;i++)
y[i]=&x[i];
for(i=4;i>=0;i--)
{ if(x[i]%2!=0)
*y[i]=*y[i]*2;
else
*y[i]=*y[i]/2;
}
for(i=1;i<6;i++)
{ cout<<x[i-1]<<"#";
if(i%3==0)
cout<<endl;
}
cout<<*y[2]*2;
}
9) Find the output of the following programming code:
int x[ ] ={10,20,30,40,50};
int *p, **q, *t;
p=x;
t= x +1;
q=&t;
cout<< *p <<’\t’ << **q <<’\t’ << (*t)++;
10) Write the output of the following
#include<iostream.h>
void main()
{
int *a,**b,c=25,***d,e=40,&f=e,*i;
a=&c;
i=&e;
b=&i;
d=&b;
cout<<c<<"-"<<e<<"-"<<*a<<"-"<<**b<<"-"<<***d<<"-"<<*i<<"-"<<f<<endl;
++c;
e--;
i=&c;
a=&e;
cout<<c<<"-"<<e<<"-"<<*a<<"-"<<**b<<"-"<<***d<<"-"<<*i<<"-"<<f<<endl;
}

You might also like