DOUBT CLEARING ZONE | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 31

DOUBT CLEARING ZONE

Doubts regarding any programming languages especially questions from challenge section can be posted here so that we may get more concepts in that area from community(see by DATE to get the correct order)

14th Apr 2018, 8:14 AM
𝘕𝘉
𝘕𝘉 - avatar
7 Answers
+ 1
int a,b; a= 1,2,3,4,5; b=(1,2,3,4,5); cout <<a <<b; Outputs: 15 How a and b outputs to 1 and 5 respetively?(It is one of the question in c++ belonging to challenge section) This code will not even get compiled, because a is expected to be an integer and so is b, but what type of a value does b have there ? There should be no outputs but an error.
16th Apr 2018, 1:08 PM
Semih Mumcu
Semih Mumcu - avatar
+ 14
int a = 10; int b= 13; int *p1=&a; int *p2=&a; *p1=b; cout <<(*p1) +(*p2); O/P :26 How??
14th Apr 2018, 10:01 AM
𝘕𝘉
𝘕𝘉 - avatar
+ 13
Ok Thank you so much Semih Mumcu 😊
14th Apr 2018, 10:24 AM
𝘕𝘉
𝘕𝘉 - avatar
+ 13
int a,b; a= 1,2,3,4,5; b=(1,2,3,4,5); cout <<a <<b; Outputs: 15 How a and b outputs to 1 and 5 respetively?(It is one of the question in c++ belonging to challenge section)
16th Apr 2018, 12:05 PM
𝘕𝘉
𝘕𝘉 - avatar
+ 1
by defining *p1=b , you basically change the variable value that &a carries which is "a". Since *p2 points to the same adress its value gets changed to b as well. Therefore *p1 and *p2 pointers are the same and equal to b which sums up to 13+13=26
14th Apr 2018, 10:14 AM
Semih Mumcu
Semih Mumcu - avatar
+ 1
cout<<a will be 13, because you changed the value to b on whatever was in &a
14th Apr 2018, 10:23 AM
Semih Mumcu
Semih Mumcu - avatar
+ 1
My pleasure ! Nirmalya Bakshi
14th Apr 2018, 10:26 AM
Semih Mumcu
Semih Mumcu - avatar