Written by students who passed Immediately available after payment Read online or as PDF Wrong document? Swap it for free 4.6 TrustPilot
logo-home
Class notes

Data Structure

Rating
-
Sold
-
Pages
84
Uploaded on
14-11-2024
Written in
2024/2025

Detailed notes of data structure and algorithms

Institution
Course

Content preview

lOMoARcPSD|40040809




Data Structures Practicals (3130702) (GTU)


computer science & engg (Government Engineering College, Bhavnagar)




Scan to open on Studocu




Studocu is not sponsored or endorsed by any college or university
Downloaded by Saroj Gandhi ()

, lOMoARcPSD|40040809




Practical 1
Aim : Introduction to pointers. Call by Value and
Call by reference.
POINTERS
The pointer in C language is a variable which stores the address of
another variable. This variable can be of type int, char, array,
function, or any other pointer. The size of the pointer depends on
the architecture. However, in 32-bit architecture the size of a
pointer is 2 byte.

Declaring and Initializing a pointer
The pointer in c language can be declared using * (asterisk symbol).
It is also known as indirection pointer used to dereference a
pointer.
int *ptrint; //pointer to int
char *ptrchar; //pointer to char
ptrint = # //initialization of pointer to an int
ptrchar = &achar; //initialization of pointer to a char

CALL BY VALUE
In call by value method, the value of the actual parameters is
copied into the formal parameters. In other words, we can say that
the value of the variable is used in the function call in the call by
value method.
In call by value method, we can not modify the value of the actual
parameter by the formal parameter.
In call by value, different memory is allocated for actual and formal
parameters since the value of the actual parameter is copied into
the formal parameter.
Downloaded by Saroj Gandhi ()

, lOMoARcPSD|40040809




Call By Value Program



#include<stdio.h>
void change(int num) {
printf("Before adding value inside function num=%d \n",num);

num=num+100;
printf("After adding value inside function num=%d \n", num);

}
int main() {
int x=100;
printf("Before function call x=%d \n", x);
change(x);//passing value in function
printf("After function call x=%d \n", x);
return 0;
}



Output :




Downloaded by Saroj Gandhi ()

, lOMoARcPSD|40040809




CALL BY REFERENCE
In call by reference, the address of the variable is passed into the function
call as the actual parameter.
The value of the actual parameters can be modified by changing the formal
parameters since the address of the actual parameters is passed.
In call by reference, the memory allocation is similar for both formal
parameters and actual parameters. All the operations in the function are
performed on the value stored at the address of the actual parameters, and
the modified value gets stored at the same address.

Call By Reference Program

#include<stdio.h>
void change(int *num) {
printf("Before adding value inside function num=%d \n",*num)
;
(*num) += 100;
printf("After adding value inside function num=%d \n", *num);

}
int main() {
int x=100;
printf("Before function call x=%d \n", x);
change(&x);//passing reference in function
printf("After function call x=%d \n", x);
return 0;
}

Ouput :




Downloaded by Saroj Gandhi ()

Written for

Institution
Course

Document information

Uploaded on
November 14, 2024
Number of pages
84
Written in
2024/2025
Type
Class notes
Professor(s)
Rashmi desai
Contains
All classes

Subjects

$4.49
Get access to the full document:

Wrong document? Swap it for free Within 14 days of purchase and before downloading, you can choose a different document. You can simply spend the amount again.
Written by students who passed
Immediately available after payment
Read online or as PDF

Get to know the seller
Seller avatar
shreelgandhi

Also available in package deal

Get to know the seller

Seller avatar
shreelgandhi Sardar Vallabbhai Patel Institute of Technology
Follow You need to be logged in order to follow users or courses
Sold
-
Member since
1 year
Number of followers
0
Documents
16
Last sold
-

0.0

0 reviews

5
0
4
0
3
0
2
0
1
0

Recently viewed by you

Why students choose Stuvia

Created by fellow students, verified by reviews

Quality you can trust: written by students who passed their tests and reviewed by others who've used these notes.

Didn't get what you expected? Choose another document

No worries! You can instantly pick a different document that better fits what you're looking for.

Pay as you like, start learning right away

No subscription, no commitments. Pay the way you're used to via credit card and download your PDF document instantly.

Student with book image

“Bought, downloaded, and aced it. It really can be that simple.”

Alisha Student

Working on your references?

Create accurate citations in APA, MLA and Harvard with our free citation generator.

Working on your references?

Frequently asked questions