The Gateway to Computer Science Excellence
First time here? Checkout the FAQ!
+2 votes

int main()
    int a = 10;
    int *b = &a;

What will be the Output of the following code if input given is $25$ ?

in Programming by (157 points)
edited by | 95 views

2 Answers

+1 vote
int main() {
 int a=10;            // value of a =10;
 int *b=&a;          // pointer b stores the address of a i.e. points to a
 scanf("%d",b);     // b gets a value from user(25) and stores it in a since b points to a
 printf("%d",a+50);  // here a = (value which user gave + 50)= 25+50 = 75
 return 0;

$\therefore$ here value of $a$ = (value which user gave + 50) = 25+50 = $75$ will be printed as output.

by Boss (17.2k points)
I'm having a doubt that b contains address of a than how can we update the value of a as=25 rather than not updating any value
Plz help with an approach for my doubt.

scanf reads data from stdin(here it is 25) and stores them according to the parameter format (here it is %d) into the locations pointed by the additional arguments.(i.e stores in location pointed by b)

we generally write scanf as scanf("%d" , &a); and here b = &a;

So we can write scanf("%d",b);

0 votes

Output 75


by (63 points)

Related questions

+1 vote
2 answers
asked Dec 18, 2017 in Programming by ashwina Active (1.7k points) | 222 views
Quick search syntax
tags tag:apple
author user:martin
title title:apple
content content:apple
exclude -tag:apple
force match +apple
views views:100
score score:10
answers answers:2
is accepted isaccepted:true
is closed isclosed:true
49,833 questions
54,797 answers
80,677 users