+ 1

How to come output 4 . can you please tell ?

#include <iostream> using namespace std; int *fun(){ return new int[2]; } int fun(int *p){ delete[]p; return 0; } void fun(int *p,int q) { p[q]*=2;} void fun(int *p,int q,int r){ p[q]=r; } int main(){ int *v=fun(); fun(v,0,1); fun(v,1,2); fun(v,0); cout<<v[1]+v[0]; fun(v); }

23rd Sep 2017, 7:41 AM
Anuj kumar
Anuj kumar - avatar
6 Answers
+ 16
Line 1 : An array of size 2. Line 2 : Element at Index 0 = 1. Line 3 : Element at Index 1 = 2. Array is [1, 2] Line 4 : Element at Index 0 is doubled. Array is [2, 2] Line 5 : Sum of elements = 2 + 2 = 4 is printed.
23rd Sep 2017, 7:59 AM
Krishna Teja Yeluripati
Krishna Teja Yeluripati - avatar
+ 11
@Anuj Kumar : The main() function in the program in your question.
23rd Sep 2017, 10:48 AM
Krishna Teja Yeluripati
Krishna Teja Yeluripati - avatar
+ 2
can any body tell the program to find the gcd of n numbers entered by user (in CPP)
23rd Sep 2017, 9:07 AM
Headshot
Headshot - avatar
+ 2
#include <iostream> using namespace std; int *fun(){ return new int[2]; } int fun(int *p){ delete[]p; // how will this work return 0; } void fun(int *p,int q) { p[q]*=2;} void fun(int *p,int q,int r){ p[q]=r; } int main(){ int *v=fun(); fun(v,0,1); // ?? fun(v,1,2); //?? fun(v,0); // ??? cout<<v[1]+v[0]; ///?? fun(v);//?? }
23rd Sep 2017, 10:54 AM
Anuj kumar
Anuj kumar - avatar
+ 1
krishna teja yeluylripati@ which program are you telling about ?
23rd Sep 2017, 10:45 AM
Anuj kumar
Anuj kumar - avatar
+ 1
well it can be more simple
23rd Sep 2017, 10:51 AM
Anuj kumar
Anuj kumar - avatar