0% found this document useful (0 votes)
45 views3 pages

C++ Code Output Analysis

The document contains multiple code snippets testing different data types and memory operations in C++. It asks the reader to determine which code snippets are correct and will compile without errors, and which will result in errors or incorrect output. It also contains several code snippets and asks the reader to predict the output of each one.

Uploaded by

Pragyakta Singh
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)
45 views3 pages

C++ Code Output Analysis

The document contains multiple code snippets testing different data types and memory operations in C++. It asks the reader to determine which code snippets are correct and will compile without errors, and which will result in errors or incorrect output. It also contains several code snippets and asks the reader to predict the output of each one.

Uploaded by

Pragyakta Singh
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/ 3

Assignment -04

1. Which of the following statements are correct?

a. #include <iostream>

using namespace std;


int main()
{
int a1=5;
float f1=5.105;
char c1=4.5;
cout <<a1<< endl;
cout <<f1<< endl;
cout <<c1<< endl;
return 0;
}
Output:
Correct

b. int a2[2]={1,2,3};
float f2[3]={1.0,2.0};
Output:
Incorrect

c. char c2[4]="ABCD";
char c3[4]={'A','B','C','D'};
Output:
Incorrect

d. char *c2[4]="ABCD";
char c3[4]={'A','B','C','D'};
Output:
Incorrect

e. char *c5[4]={'A','B','C','D'};
char c3[4]={'A','B','C','D'};
Output
Incorrect
Q2. Check output of the following:
1. #include <iostream>
using namespace std;
int main()
{
int a3=5;
int *p=&a3;
cout<<p<< endl<<*p;
return 0;
}

Output:
0x61ff08
5
2. int a4=5.5,6.5;
int *p=&a4;
cout<<a4;
Output:
Error
3. int a5=(5,6);
cout<<a5;
Output:
6
4. int a6[]={5,6};
cout<<a6[0]<<endl<<a6[1];
Output:
5
6
5. int a7[4]={1,2,3,4};
int *p=&a7[3];p--;
cout<<*p;
Output:
3
6. int a8[4]={1,2,3,4};
int *p=&a8[1];
for(int i=-1;i<=3;i++)
cout<<p[i]<<endl;
Output:
1
2
3
4
6422268
7. int a9=5;;
int p1=&a9;
int &p2=a9;
cout <<p2<<endl<<&p2<<endl;
cout<<p1<<endl<<p2;
Output:
Error
8. int a8[4]={1,2,3,4};
int *p1=&a8[0];
int p2=&a8[0];
int &p3=a8[0];
cout <<*p1<<*++p1<<*++p1;
cout <<*p1<<p1<<*++p1;
Output:
Error
9. char c5='A';
char *p=&c5;
cout<<p;
char *c6='A';
char *c6[2]={"A","B"}
char *p=c6;
cout<<p;
char c7="ABCD";
char **p=&c7;
cout<<p;
Output:
error

You might also like