pointers and arrays in c++
#include <iostream> using namespace std; int main() { int x[3] = { 5,9,20 }; int* p = x; cout << p << endl; //prints the address of x[0] cout << *p << endl; //prints the value of x[0] (5) //printing the array for (int i = 0; i < 3; i++){ cout << p[i] << endl; //or cout << *(p + i) << endl; } }
C++ Pointers and Arrays
int *ptr; int arr[5]; // store the address of the first // element of arr in ptr ptr = arr;
arrays and pointers
#include<stdio.h> int main() { int arr[5] = {10, 20, 30, 40, 50}, i; for(i = 0; i < 5; i++) printf("Address of arr[%d] = %p\n",i,arr+i); return 0; }
Source: www.log2base2.com
arrays and pointers
#include<stdio.h> int main() { int arr[5] = {10, 20, 30, 40, 50}, i; for(i = 0; i < 5; i++) printf("value stored in arr[%d] = %d\n",i,*(arr+i)); return 0; }
Source: www.log2base2.com