Pointers_Basics
Pointers_Basics
int Quantity =
50;
• This statement instructs the system to find a location for the
integer variable Quantity and puts the value 50 in that location.
• Assume that system has chosen address location 5000 for Quantity
• Invalid Cases:
&50 (pointing at constant)
int x[10];
&x (pointing at array name)
&(x + y) (pointing at expressions).
• If x is an array, then expressions such as &x[0] and
&x[i+3] are valid and represent the addresses of 0th
and (i+3)th elements of x.
• Element in 2d represented as
*(*(a+ i )+j) or
* (* ( p + i )+ j)
struct inventory
{
char name[30];
int number; float price;
}product[2], ∗ptr;
• ptr=product;
• Its members are accessed
using the following
notation
ptr→name
ptr→number
ptr→price
Apr 6, 2025 Dept of I&CT 30 / 37
Pointers and Structures
• The symbol → is called arrow operator (also known as member
selection operator)
• The data members can also be accessed using
• (*ptr).number
• Parentheses is required because ’.’ has higher precedence than the
operator *
• Memory de-allocation
free(pointer variable)
Explain with structures