You are on page 1of 2

Experiment no 4.

TO DEMONSTRATE PASSING STRING TO FUNCTION

THEORY
Strings are sequence of characters used in programming language for storing and manipulating
texts such as words, sentence, names etc. In C, there is no built-in data type for strings. String can be
represented as a one-dimensional array of characters. A character string is stored in an array of
character type. In C, just like variables strings can be passed to a function. The strings can be passed to
other function to carry out different operations.

DEMONSTRATION

Program 1: To read and display the string using functions.

#include <stdio.h>
void studentData(int rollno , char *name , float marks)
{
printf("\nName is : %s",name);
printf("\nRoll No. is : %d",rollno);
printf("\nMarks are : %f ",marks);
}
int main()
{
int rollno;
float marks;
char name[20];
printf("Enter Name::");
scanf("%s",&name);
printf("Enter roll no::");
scanf("%d",&rollno);
printf("Enter marks::");
scanf("%f",&marks);

studentData(rollno , name , marks);


return 0;
}
Output:
Experiment no 4.5

Discussion:
In above program, the string is passed to a function to carry out the operation.
CONCLUSION
Hence, passing string to function was demonstrated.

You might also like