Output writing – Pointer to array – CSKC
Sign In

Search





Q&A #5204 siteicon  

Question:

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


Share

C. Sir| Created: 3-Dec-2018 | Updated: 22-Mar-2026|CBSE12A-2018









×
ssignment Introductory Sessions Beginning to Program Tokens Keyword and Identifiers Data Types Variables and Constants Operators Simple User Input Building Expressions and Formulas Simple Real World Problems Simple If and If Else Multiple-Nested-Ladder of If Else Switch case selection Simple Loops Tricks in Loops - break continue scope Loop Applications - Handling numerals Series printing loops Nested Loops Pattern printing loops Number Varieties and Crunches String Handling (Null Terminated) Strings - string class type Functions (Built-in) Functions - user defined Functions Reference Passing/Returning Arrays Concepts and 1-D Arrays Array Data Management Two dimensional arrays and Matrices Structures Basics Structures passing/returning Display Using IO Manipulation User Defined Data Types Enumerated Types Preprocessor Directives And Macros Programming Paradigms and OOPs Advantages Abstraction and Encapsulation Polymorphism Inheritance Function Overloading Concepts Function Overloading Varieties Defining Classes Creating and Using Class Objects Class Members Accessibility Class Function Types Inline Functions Constructor Concepts Default Constructor Copy Constructor Constructor Overloading Destructors Inheritance Fundamentals Public Derivations Private and Protected Derivations Multiple Inheritance Mult-Level Inheritance Data File Concepts Handling Text Files Handling Binary Files Pointer Concepts Pointer and Arrays Stacks Queues Introductory Sessions Beginning to Program Tokens Keywords Identifiers Literals Data Types Variables and Constants Operators (Arithmetic-Assignment-Unary-Relational-Logical) Expressions Statements and Formula Based Calculations Class Object Creation and Access Wrapper Classes Constructor Basics Conversion and Checking Functions Math Functions Function building and calling Simple If and If-Else Selection Switch Based Selections Basic Loop Types Array Basics Array Search Array Sorting Character Handling String Basics String Class Functions Types of Errors Try Catch Introductory Sessions Beginning to Program Introductory Sessions Beginning to Program Introductory Sessions Beginning to Program Data Types Variables and Constants Introductory Sessions Beginning to Program Date and Time Handling Regular Expressions Command Line Arguments Concurrent Execution Making Executable File Python Introduction (Features Python Introduction (Features, Installation, Modes) Handling Unicode Internet Interactions Imaging and Compression Special Data File Handling Python Basics Cryptography Blockchain and Cryptocurrency Generative AI keywords, identifiers, variables Beginning To Program Tokens, Keywords, Identifiers Variables and Expressions Data Types Operators Concept Learning Examples Operators Solved Practical Examples elational nary)