Create a free account on Computer Sir Ki Class and unlock access to valuable learning resources.
Exam Paper Downloads: After registering and logging in, you can download exam question papers in PDF format to practice and prepare for your exams.
Student Support: Get assistance with your doubts, queries, and questions related to your studies. Our support is here to help you understand topics and resolve your learning difficulties.
Register today and make your exam preparation easier and more effective!
Find and write the output of the following C++ program code:
Note : Assume all required header files are already included in the program.
#define Modify(N) N*3+10
void main()
{
int LIST[]={10,15,12,17};
int *P=LIST, C;
for(C=3; C>=0; C--)
LIST[I]=Modify(LIST[I]);
for (C=0; C<=3; C++)
{
cout<<*P<<":";
P++;
}
}
Answer:
This was a question that created controversy as the variable I was not declared. CBSE declared that if the student has given error as response then full marks would be awarded.
The corrected question can however be as follows.
#define Modify(N) N*3+10
void main()
{
int LIST[]={10,15,12,17};
int *P=LIST, C;
for(C=3; C>=0; C–)
LIST[C]=Modify(LIST[C]);
for (C=0; C<=3; C++)
{
cout<<*P<<“:”;
P++;
}
}
The answer to corrected question would be – 40:55:46:61:
Notes:
#define Modify(N) N*3+10
This is a define macro which will take a value in N and will process it by multiplying N y 3 and then adding 10 to it.
int LIST[]={10,15,12,17};
This is an integer array with 4 members initialised as 10, 15, 12 and 17
int *P=LIST, C;
*P represents pointers to first member of LIST array and and C is another integer variable.
for(C=3; C>=0; C–) LIST[C]=Modify(LIST[C]);
All the members of LIST array will be modified based on define macro calculation, so practically every initial member will be multiplied by 3 and added with 10. which means it will become 40, 55, 46 and 61 respectively. This loop will however traverse in reverse order from last member of array to first member which is at index 0.
for (C=0; C<=3; C++) { cout<<*P<<“:”; P++;} This loop will simply print the array members by incrementing array pointer. *P prints value at each pointer location. So the output would be 40:55:46:61
C. Sir| Created: 3-Dec-2018 | Updated: 22-Mar-2026|CBSE12A-2018