0% found this document useful (0 votes)
29 views9 pages

Understanding Recursion and Pointers in C

Uploaded by

yeasir arafat
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
29 views9 pages

Understanding Recursion and Pointers in C

Uploaded by

yeasir arafat
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Lecture-2

Self Referential Structure


RECALLING RECURSION

• A programming technique where a


function calls itself
• Breaking down a complex problem
into smaller, more manageable
subproblems

sazzad@diucse
POINTERS
➢ Pointer is a variable that
stores the address of
another variable.
➢ Pointer points to the
memory location of the
variable whose address is
provided

sazzad@diucse
POINTERS

Basic syntax:
int var = 10 10

DataType *Var_Name; #1010

Example: int *ptr = &var #1010

int *p #5006

sazzad@diucse
Address (&) Operator
The address (&) operator can be used in front of any variable object in
C -- the result of the operation is the location in memory of the
variable.

Syntax: &VariableReference

Examples:

int a;
printf(“%d”,&a);

sazzad@diucse
Pointer Variable Initialization/Assignment
NULL - pointer lit constant to non-existent address
– used to indicate pointer points to nothing
Can initialize/assign pointer vars to NULL or use the address (&) op to
get address of a variable
– variable in the address operator must be of the right type for the pointer (an
integer pointer points only at integer variables)
Examples:
int a;
int *p;
p = &a;
printf(“%d”,*p);
printf(“%d”,&p);
sazzad@diucse
Pointer Sample

int A = 3; Q = &B;
int B; if (P == Q)
int *P = &A; printf(“1\n”);
int *Q = P; if (Q == R)
int *R = &B; printf(“2\n”);
if (*P == *Q)
printf(“Enter value:“); printf(“3\n”);
scanf(“%d”,R); if (*Q == *R)
printf(“%d %d\n”,A,B); printf(“4\n”);
printf(“%d %d %d\n”,*P,*Q,*R); if (*P == *R)
printf(“5\n”);

sazzad@diucse
Structure

• The structure in C is a user-defined data


type that can be used to group items of
possibly different types into a single
type.

sazzad@diucse
Thank You

sazzad@diucse

You might also like