This document provides an introduction to arrays and pointers for beginner programmers. It explains what arrays and pointers are, how to declare and initialize them, and includes examples of common operations like accessing element values, taking addresses, and dereferencing pointers. Demo code is provided to illustrate summing array elements, finding maximum values, reversing an array, and printing two-dimensional arrays and pointers. The document aims to explain basic array and pointer concepts without advanced mathematics to help beginners learn programming fundamentals.
2. Target Audience
People who have no prior coding experience, didn’t take
CS101 seriously but want to learn some basics of coding
quickly.
If you know how write a program to sum up numbers in an
array, and you DO NOT faint on seeing int ***ptr, then
please don’t your waste time here; this tutorial is not for
you.
3. Data types
● int : -1000, -5, 0, 10, 2014
● char : a, @, +
● float : -10.35, 2.578
● bool : True/False
4. More Data types
● Array - {1,2,3,4}
● String - “Ghissu”
● Pointers
16. Address of Variables
● int x = 10; //value of x is 10
● address of variable x is &x
x
10
0x7fff4d84231c
Variable Name
Data/Content
Address of variable
22. Pointer Dereferencing
int *ptr;
ptr = &x;
cout<<ptr;
cout<<*ptr;
Pointer Declaration
Making ptr point to x (x MUST be int)
Will print address of x
Will print the value stored at x
6
0x7fff4d84231c
ptr
x
28. 0 1 2 3 4 5 6
- 22 - 33 - 44 - 55 - 66 - 77 - 88
0014 0018 0022 0026 0030 0034 0038
arr[0] is same as *(arr + 0) is same as -22
&(arr[0]) is same as (arr + 0) is same as 0014
arr[1] is same as *(arr + 1) is same as -33
&(arr[1]) is same as (arr + 1) is same as 0018
arr[5] is same as *(arr + 5) is same as -77
&(arr[5]) is same as (arr + 5) is same as 0034
Array Index
int arr[7]
Address
arr
29. To be continued ...
● Dynamic memory allocation
● C-style strings.
● strcmp, strcat etc.