Download presentation
Presentation is loading. Please wait.
1
CSCE 206 Lab Structured Programming in C
Fall 2018 Lecture 6 Ehsanul Haque Nirjhar
2
Pointer Pointers are variables that stores/points the address of another variables Address refers to the memory location of a variable
3
Pointer operators & is the address operator. It refers to the address of a variable. * is the dereference operator. It refers to value at a specific address. Why pointer? Call by reference Dynamic Memory Allocation
4
Pointer int main(void) { int var = 50; int *ptr; ptr=&var; printf("value is %d\n", var); printf("value is %d\n", *ptr); printf("Address of value is %d", ptr); return 0; } Prints: value is 50 Address of value is 1001
5
Practice Problem-1 Write a program that adds 2 integers using pointer approach. Take 2 integers in 2 variables named a and b. Add those numbers and save it in another variable. Print the address and values of a,b and c.
6
Practice Problem-2 Write a program that takes 3 integers as input and find the largest number among them. Use pointer variables to do the comparison and output printing.
7
Practice Problem-3 Write a program that takes 2 integers as input and swap their values. You are required to write a function named SwapValues, that takes 2 pointer variables and within the function swap the values. Print the output from main function.
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.