Lecture Introduction to computer and programming - Lecture No 15

This chapter examines some more advanced concepts related to process management, which are found in a number of contemporary operating systems. We show that the concept of process is more complex and subtle than presented so far and in fact embodies two separate and potentially independent concepts: one relating to resource ownership and another relating to execution. | CSC103: Introduction to Computer and Programming Lecture No 15 Previous lecture Menu driven program using functions Function call by value Scope of variable Local Global Today’s lecture outline Pointer fundamental & operator * operator Pointer declaration Pointer type Simple variable declaration Consider the declaration, This declaration tells the C compiler to: Reserve space in memory to hold the integer value Associate the name i with this memory location Store the value 3 at this location Memory i 3 65520 Value at location Location name Location number or address Address – a class room example 1 2 3 4 5 4 3 2 1 Address of this chair (2, 3) 2nd row and 3rd column (5, 2) A program to print memory address Output of program Address of i = 65520 Value of i = 3 & used in this statement is C’s ‘address of’ operator Go to program Cont. Memory f 70020 Value at location Location name Location number or address ch a 85690 * operator The pointer operator available in C is *, called ‘value at address’ operator It gives the value stored at a particular address The ‘value at address’ operator is also called ‘indirection’ operator Example program i 3 85065 Program output Address of i = 85065 Value of i = 3 Value of i = 3 * (&i) = *(85065) = 3 Go to program Cont. We can store the address of variable i in a variable say p, . p = &i; p is not an ordinary variable It is a special variable that contains address of other variable Compiler also provide a space in memory for p like it do for other variables Cont. Memory p 3 i 85065 76950 p = &i; p = 85065 85065 i’s value is 3 and p’s value is i’s address Pointer declaration *p 3 i 85065 76950 85065 *(&i) =*(85065) = 3 85065 85065 76950 85065 3 3 3 *p = *(85065) = 3 Go to program Points to remember Pointers are variables that contain a memory address as their value In other words, a pointer variable contains a memory address that points to another variable * operator means “value at address” & operator means “address of” . | CSC103: Introduction to Computer and Programming Lecture No 15 Previous lecture Menu driven program using functions Function call by value Scope of variable Local Global Today’s lecture outline Pointer fundamental & operator * operator Pointer declaration Pointer type Simple variable declaration Consider the declaration, This declaration tells the C compiler to: Reserve space in memory to hold the integer value Associate the name i with this memory location Store the value 3 at this location Memory i 3 65520 Value at location Location name Location number or address Address – a class room example 1 2 3 4 5 4 3 2 1 Address of this chair (2, 3) 2nd row and 3rd column (5, 2) A program to print memory address Output of program Address of i = 65520 Value of i = 3 & used in this statement is C’s ‘address of’ operator Go to program Cont. Memory f 70020 Value at location Location name Location number or address ch a 85690 * operator The pointer operator available in C is *, called ‘value

Bấm vào đây để xem trước nội dung
TÀI LIỆU MỚI ĐĂNG
308    10    1    12-06-2024
97    369    1    12-06-2024
Đã phát hiện trình chặn quảng cáo AdBlock
Trang web này phụ thuộc vào doanh thu từ số lần hiển thị quảng cáo để tồn tại. Vui lòng tắt trình chặn quảng cáo của bạn hoặc tạm dừng tính năng chặn quảng cáo cho trang web này.