100% satisfaction guarantee Immediately available after payment Both online and in PDF No strings attached
logo-home
Data Structure $3.99   Add to cart

Class notes

Data Structure

 1 view  0 purchase
  • Course
  • Institution

Detailed notes of data structure and algorithms

Preview 4 out of 84  pages

  • November 14, 2024
  • 84
  • 2024/2025
  • Class notes
  • Rashmi desai
  • All classes
avatar-seller
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 (gandhisaroj300@gmail.com)

, 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 (gandhisaroj300@gmail.com)

, 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 (gandhisaroj300@gmail.com)

, 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 (gandhisaroj300@gmail.com)

The benefits of buying summaries with Stuvia:

Guaranteed quality through customer reviews

Guaranteed quality through customer reviews

Stuvia customers have reviewed more than 700,000 summaries. This how you know that you are buying the best documents.

Quick and easy check-out

Quick and easy check-out

You can quickly pay through credit card or Stuvia-credit for the summaries. There is no membership needed.

Focus on what matters

Focus on what matters

Your fellow students write the study notes themselves, which is why the documents are always reliable and up-to-date. This ensures you quickly get to the core!

Frequently asked questions

What do I get when I buy this document?

You get a PDF, available immediately after your purchase. The purchased document is accessible anytime, anywhere and indefinitely through your profile.

Satisfaction guarantee: how does it work?

Our satisfaction guarantee ensures that you always find a study document that suits you well. You fill out a form, and our customer service team takes care of the rest.

Who am I buying these notes from?

Stuvia is a marketplace, so you are not buying this document from us, but from seller shreelgandhi. Stuvia facilitates payment to the seller.

Will I be stuck with a subscription?

No, you only buy these notes for $3.99. You're not tied to anything after your purchase.

Can Stuvia be trusted?

4.6 stars on Google & Trustpilot (+1000 reviews)

75759 documents were sold in the last 30 days

Founded in 2010, the go-to place to buy study notes for 14 years now

Start selling
$3.99
  • (0)
  Add to cart