Docsity

L-8 Pointer.pptx (), Lecture notes of Computer Engineering and Programming

Partial preview of the text

Download L-8 Pointer.pptx () and more Lecture notes Computer Engineering and Programming in PDF only on Docsity!

Pointer

Memory Chip

Inside a house(smallest unit in memory chip)!!!

A unique Address

8 rooms = 8 bits = 1 byte

06/02/2026 Md. Mehedi Hasan, Lecturer, EEE, JUST Address Card

8 123 ABC ST p

06/02/2026 Md. Mehedi Hasan, Lecturer, EEE, JUST 10 Pointer Variables

  • (^) The general form for declaring a pointer variable is

type *name;

For example, short int *j;

  • (^) when you declare a pointer to be of type int *, the compiler assumes that any

address that it holds, points to an integer.

For, float *x; the compiler assumes that any address that x holds, points to an

floating point object.

  • (^) Always remember, that the value of a pointer in C is meaningless until it is set

pointing to something.

06/02/2026 Md. Mehedi Hasan, Lecturer, EEE, JUST 11 The & and ***** Pointer Operators

  • (^) The first pointer operator is & , a unary operator that returns the memory address of its operand. The above statement places the memory address of the variable i into j.
  • (^) This address is the computer's internal location of the variable. It has nothing to do with the value of i.
  • (^) You can think of & as meaning ' 'the address of". Location address Location name Value at Location

06/02/2026 Md. Mehedi Hasan, Lecturer, EEE, JUST 13 Another pointer operator is __* places the value at the address that j is holding( address of i) into q.

  • (^) The variable that holds the address of another variable is called pointer variable.
  • (^) You can think of * as meaning “ at address ”.
  • (^) In this case, you could read the statement as "q receives the value at address j(the address j is holding, not the address of j)." q = *j;

q

06/02/2026 Md. Mehedi Hasan, Lecturer, EEE, JUST 17

  • (^) Swap - Interchange the value of two variables using

#include^ function

void swap(int x, int y); int main() { int a=10,b=20; swap(a,b); printf("%d\n",a); printf("%d",b); return 0; } void swap(int x, int y) { int temp; temp = x; x = y; y = temp; } Does this function work properly?

 We might not want to change the value of the variable we are

passing!!