home
search
help
profile
liking the experience? our app is even better
registration for
employee referral programs
are now open
get referred to google, amazon, flipkart and more
register now  
showing results for pointers vs reference variables
1Variable is used to store value
2Pointer is used to store addresss of value
upvote
downvote
source
1/*
2**use of pointers is that here even if we change the value of c since the adderss is
3* of c is assigned to pc it *pc will also get modified*/
4int* pc, c;
5c = 5;
6pc = &c;
7*pc = 1;
8printf("%d", *pc);  // Ouptut: 1
9printf("%d", c);    // Output: 1
10
upvote
downvote
source
1As discussed earlier, 'p' is a pointer to 'a'. Since 'a' has a value of 10, so '*p' is 10. 'p' stores the address of a. So the output p = 0xffff377c implies that 0xffff377c is the address of 'a'. '&p' represents the address of 'p' which is 0xffff3778. Now, '*&p' is the value of '&p' and the value of '&p' is the address of 'a'. So, it is 0xffff377c.
upvote
downvote
source
1#include <iostream>
2
3float average(float a[])
4{
5    int i;
6    float avg, sum=0;
7    for(i=0;i<8;++i)
8    {
9        sum+= a[i];
10    }
11    avg = sum/8;
12    return avg;
13}
14
15int main(){
16	float b, n[ ] = { 20.6, 30.8, 5.1, 67.2, 23, 2.9, 4, 8 };
17	b = average(n);
18  	std:: cout << "Average of numbers = " << b << std::endl;
19	return 0;
20}
21
upvote
downvote
source
1Size of arr[] 24
2Size of ptr 4
upvote
downvote
source
1#include <iostream>
2// by using increment sign we know whole array
3int main()
4{
5	using namespace std;
6	int ar[] = { 1,2,3,4,5,6,7,8,9,10 };
7	for (int m : ar)
8	{
9		cout << m << endl;
10	}
11	return 0;
12}
13
upvote
downvote
source
1p = 0xffff377c
2*p = 10
3&p = 0xffff3778
4*&p = 0xffff377c
upvote
downvote