Docsity

C programming just a piece of code, Study notes of C programming

Toggle sidebar
bg1
Page no: - ___ of___
Roll No: -
Class/ batch: -
Subject: -
DOP: -
DOS: -
Grade: -
Signature: -
Problem Statement:
a. Write a function to swap two integers using call by reference.
b. Write a program to display contents of array using pointers
Theory:
In programming languages, we have a concept of variable. These variables are used to
hold values in them. One can use such variables while programming. However, there
are few tasks that do not require variables but requires the address of those variables.
The address of variables means the memory location actual where these variables are
existing . We can define a pointer as a type of variable that holds the address of any
other variable that might be holding some value.
There are two ways by which we can actually print the address of a variable.
โ—By using ampersand ( & ) method
โ—By using pointer
1. By using an ampersand (&) method
In this method, we will be using the concept of the ampersand to print the address of a
variable.
2. By using pointer
This is a modern approach to access the address of a variable.
Experiment No. 10
pf3
pf4
pf5

Partial preview of the text

Download C programming just a piece of code and more Study notes C programming in PDF only on Docsity!

Roll No: - Class/ batch: - Subject: - DOP: - DOS: - Grade: - Signature: - Problem Statement: a. Write a function to swap two integers using call by reference. b. Write a program to display contents of array using pointers Theory: In programming languages, we have a concept of variable. These variables are used to hold values in them. One can use such variables while programming. However, there are few tasks that do not require variables but requires the address of those variables. The address of variables means the memory location actual where these variables are existing. We can define a pointer as a type of variable that holds the address of any other variable that might be holding some value. There are two ways by which we can actually print the address of a variable. โ— By using ampersand ( & ) method โ— By using pointer

1. By using an ampersand (&) method In this method, we will be using the concept of the ampersand to print the address of a variable. 2. By using pointer This is a modern approach to access the address of a variable. Experiment No. 10

The general syntax of declaring a pointer. data_type *variable **Where *** denotes that the variable declared is a pointer. a variable is simply used for accessing the value. Algorithm: - (can be written on blank side of page) Flowchart: - (can be drawn on blank side of page) Program: - Output: - Conclusion : In this way we studied and executed the pointer concept. Code:- a. #include <stdio.h> void swap(int *, int *); //prototype of the function int main() { int a = 10; int b = 20; printf("Before swapping the values in main a = %d, b = %d\n",a,b);

#include <stdio.h> int main() { int data[5]; printf("Enter elements: "); for (int i = 0; i < 5; ++i) scanf("%d", data + i); printf("You entered: \n"); for (int i = 0; i < 5; ++i) printf("%d\n", *(data + i)); return 0; } Output