pointer
Variable is used to store value
Pointer is used to store addresss of value
pointer
Variable is used to store value
Pointer is used to store addresss of value
pointer
/*
**use of pointers is that here even if we change the value of c since the adderss is
* of c is assigned to pc it *pc will also get modified*/
int* pc, c;
c = 5;
pc = &c;
*pc = 1;
printf("%d", *pc); // Ouptut: 1
printf("%d", c); // Output: 1
pointer
As 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.
pointer
#include <iostream>
float average(float a[])
{
int i;
float avg, sum=0;
for(i=0;i<8;++i)
{
sum+= a[i];
}
avg = sum/8;
return avg;
}
int main(){
float b, n[ ] = { 20.6, 30.8, 5.1, 67.2, 23, 2.9, 4, 8 };
b = average(n);
std:: cout << "Average of numbers = " << b << std::endl;
return 0;
}
pointer
#include <iostream>
// by using increment sign we know whole array
int main()
{
using namespace std;
int ar[] = { 1,2,3,4,5,6,7,8,9,10 };
for (int m : ar)
{
cout << m << endl;
}
return 0;
}
pointer
p = 0xffff377c
*p = 10
&p = 0xffff3778
*&p = 0xffff377c
pointer
Size of arr[] 24
Size of ptr 4
Copyright © 2021 Codeinu
Forgot your account's password or having trouble logging into your Account? Don't worry, we'll help you to get back your account. Enter your email address and we'll send you a recovery link to reset your password. If you are experiencing problems resetting your password contact us