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

Exercise Solved

The document contains multiple C++ code snippets demonstrating the use of pointers, arrays, and basic input/output operations. It includes examples of manipulating numeric and character data, swapping values using pointers, and converting strings to different cases. Each code block illustrates different programming concepts such as pointer arithmetic, memory addresses, and string manipulation.

Uploaded by

babaralihaider74
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)
5 views6 pages

Exercise Solved

The document contains multiple C++ code snippets demonstrating the use of pointers, arrays, and basic input/output operations. It includes examples of manipulating numeric and character data, swapping values using pointers, and converting strings to different cases. Each code block illustrates different programming concepts such as pointer arithmetic, memory addresses, and string manipulation.

Uploaded by

babaralihaider74
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

#include <iostream>

using namespace std;


int main ()
{
double numbers[] = {0.0,1.1,2.2,3.3,4.4,5.5,6.6,7.7,8.8,9.9};
const int size = 10;
double* nptr = numbers;
for (int i = 0; i < size; i++)
{
cout<<numbers[i]<<" ";
}
cout<<"\n";
nptr=&numbers[0];
for (int i = 0; i < size; i++)
{
cout<<*(nptr+i)<<" ";
}
cout<<"\n";
for (int i = 0; i < size; i++)
{
cout<<*(numbers+i)<<" ";
}
cout<<"\n";
for (int i = 0; i < size; i++)
{
cout<<nptr[i]<<" ";
}
cout<<"\n";
cout<<*(numbers+3)<<"\n";
cout<<*(nptr+3)<<"\n";
cout<<numbers[3]<<"\n";
cout<<nptr[3]<<"\n";
cout<<nptr+8<<"\n";
cout<<*(nptr+8)<<"\n";
nptr=&numbers[5];
cout<<nptr<<"\n";
nptr-=4;
cout<<nptr<<"\n";
}
#include <iostream>
using namespace std;

int main() {
float num1 = 7.3;
float num2;

float* ptr = &num1;


cout<<*(ptr)<<"\n";
num2 = *ptr;
cout<<num2<<"\n";
cout<<ptr<<"\n";
cout<<&num1<<"\n";

}
#include<iostream>
using namespace std;
void exchange (double* x, double* y);
int main ()
{
double x = 2.5,y=1.5;
double* xptr = &x;
double* yptr = &y;
cout<<"values before swap:"<<*xptr<<" "<<*yptr<<"\n";
exchange(xptr,yptr);
}
void exchange(double* x , double* y)
{
double temp = *x;
*x = *y;
*y = temp;
cout<<*x<<" "<<*y<<"\n";
}
#include <iostream>
#include<string>
#include<cstring>
#include<iomanip>
#include<algorithm>
using namespace std;
int main()
{
char s[] = {'A','E','I','O','U','\0'};
int length= 0;
while (s[length]!='\0')
{
length++;
}
cout<<length<<"\n";
for (int i = 0; i < length; i++)
{
cout<<s[i]<<" ";
}
for (int i = 0; i < strlen(s); i++)
{
s[i]=tolower(s[i]);
}
cout<<"\n";
string str = "aeiou";
for (int i = 0; i < str.size(); i++)
{
str[i]=toupper(str[i]);
}
cout<<str<<"\n";

#include<iostream>
using namespace std;
int main ()
{
unsigned int values[] = {2,4,6,8,10};
const int size = 5;
unsigned int* vptr = &values[0];
for (int i = 0; i < size; i++)
{
cout<<values[i]<<" ";
}
cout<<"\n";
for (int i = 0; i < size; i++)
{
cout<<*(values+i)<<" ";
}
cout<<"\n";
for (int i = 0; i < size; i++)
{
cout<<*(vptr+i)<<" ";
}
cout<<"\n";

for (int i = 0; i < size; i++)


{
cout<<vptr[i]<<" ";
}
cout<<"\n";
cout<<values[4]<<"\n";
cout<<vptr[4]<<"\n";
cout<<*(values+4)<<"\n";
cout<<*(vptr+4)<<"\n";
cout<<vptr+3<<"\n";
cout<<*(vptr+3)<<"\n";
vptr = &values[4];
vptr-=4;
cout<<vptr<<" "<<*(vptr)<<"\n";

}
#include<iostream>
using namespace std;
int main()
{
long value1 = 5;
long value2;
long* ptr = &value1;
cout<<*ptr<<"\n";
value2 = *ptr;
cout<<value2<<"\n";
cout<<&value1<<"\n";
cout<<ptr<<"\n";

}#include<iostream>
using namespace std;
void BigIn(long int bigInt[]);
int smalli(long int smallInt[]);
int main ()
{
long bigInt [] = {1,2,3,4,5};
long smallInt []= {1,1,1,1,1};
BigIn(bigInt);
cout<<"\n"<<smalli(smallInt);

}
void BigIn(long bigInt[])
{
for (int i = 0; i < 5; i++)
{
cout<<bigInt[i]<<" ";
}

}
int smalli(long smallInt[])
{
int sum = 1;
for (int i = 0; i < 5; i++)
{
sum+=smallInt[i]+1;
}
return sum;

}
#include<iostream>
#include<string>
#include<iomanip>
using namespace std;
int main()
{
string name ;
cout<<"Enter your name:";
getline(cin,name);
string* ptr = &name;
cout<<ptr<<"\n";
int num = 355;
double nnum = 23.332;
cout<<uppercase<<hex<<num<<"\n";
cout<<uppercase<<scientific<<nnum<<"\n";
int* nptr = &num;
cout<<nptr<<"\n";
cout<<oct<<*nptr<<"\n";

You might also like