Lec 9
Lec 9
Array of Strings
It can be declared as:
static char[MAX][LEN]
Where
MAX: is the array size,
LEN: is the maximum string length
Initialization of Array of
Strings
#define MAX 5
#define LEN 40
Static char list[MAX][LEN]={“String1”, “String2”, “String3”, “String4”,
“String5”};
Ex_40
Chapter 7
Pointers
المؤشرات
Objective
What is the pointers
The function of the pointer
How to use Pointers
What is the pointer?
A pointer is a variable which contains the
address in memory of another variable. We
can have a pointer to any variable type.
Ex: int *pointer;
The Function of the Pointers
We can use Pointers to
1. Return more than value from a function
2. Passing array to a function
3. Exchange data in the memory
“Pointer are a fundamental part of C. If you cannot use pointers properly then you have
basically lost all the power and flexibility that C allows. The secret to C is in its use of
pointers.”
Pointer constant and Pointer
الثابت المؤشر والمتغيرVariable
المؤشر
يمكن تعريف الثابت المؤشر بأنه عنوان للذاكرة بينما
يعرف المتغير المؤشر بانه مكان أو موقع لتخزين
العناوين و لتعريف المتغير المؤشر يجب اضافة * بعد
نوع المتغير الذي سيشير إليه كمثال float *pf
;int x =5 5
x
;int *px
px 1500
;px = &x
Indirect Operator
مؤشر الوصول غير المباشر
إذا أضيفت عالمة المؤشر لمتغير اثناء عملية
التخصيص فهذا يعني انه مؤشرالوصول غير المباشر
مؤشرالوصول غير المباشر :يخصيص القيمة للمتغير
التي يشير إلية المتغير
*;x = 7
This means that the x is a pointer and the
value 7 will be assigned to the variable that
the x point to
Example
#include<stdio.h>
main()
{
int x;
int *px;
x = 5;
px = &x;
printf("the variable x address is %u, and the value in it is%d\n“ ,&x ,x);
printf("the variable x address is %u, and the value in it is%d\n", px ,*px);
*px = 7;
printf("the variable x address is %u, and the value in it is%d\n“ ,&x ,x);
printf("the variable x address is %u, and the value in it is%d\n", px ,*px);
Ex_41.c
Example
*px = 7
x 7
x 5
px 1500
px 1500
Example Ex_41
#include<stdio.h>
ret2(int *px,int *py);
main()
{
int x = 0;
int y = 0;
ret2(&x,&y);
printf("The first value is %d and second value is %d",x,y);
}
ret2(px,py)
int *px,*py;
{
*px = 3; The first value is 3 and second value is 7
*py = 7;
}
Example
#include<stdio.h>
ret2(int x,int y);
main()
{
int x = 0;
int y = 0;
ret2(x,y);
printf("The first value is %d and second value is %d",x,y);
}
ret2(x,y)
int x,y;
{
x = 3;
y = 7;
} The first value is 0 and second value is 0
Thanks