The Wayback Machine - https://web.archive.org/web/20240213201412/https://www.geeksforgeeks.org/use-scanf-not-printf/
Open In App
Related Articles

Use of & in scanf() but not in printf()

Improve
Improve
Improve
Like Article
Like
Save Article
Save
Report issue
Report

Why there is need of using ‘&’ in case of scanf function while not in case of printf function. Examples:

scanf("%d %d", &a, &b);
printf("%d %d", a, b);

As a and b above are two variable and each has their own address assigned but instead of a and b, we send the address of a and b respectively. The reason is, scanf() needs to modify values of a and b and but they are not local to scanf(). So in order to reflect changes in the variable a and b of the main function, we need to pass addresses of them. We cannot simply pass them by value. But in case of printf function as we are only going to print the values of the variables in output console, there are no changes going to be made in variable a and b’s values. So it is not required to send their addresses.

Whether you're preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape, GeeksforGeeks Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we've already empowered, and we're here to do the same for you. Don't miss out - check it out now!

Looking for a place to share your ideas, learn, and connect? Our Community portal is just the spot! Come join us and see what all the buzz is about!


Last Updated : 03 Jul, 2023
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads