Found 1339 Articles for C

How to pass the address of structure as an argument to function in C?

Bhanu Priya
Updated on 24-Mar-2021 13:56:39

8K+ Views

There are three ways by which the values of structure can be transferred from one function to another. They are as follows −Passing individual members as arguments to function.Passing entire structure as an argument to function.Passing the address of structure as an argument to function.Now, let us understand how to pass the address of structure as an argument to function.The address of the structure is passed as an argument to the function.It is collected in a pointer to structure in function header.AdvantagesThe advantages of passing the address of structure as an argument to function are as follows −No wastage of ... Read More

How to pass an entire structure as an argument to function in C?

Bhanu Priya
Updated on 24-Mar-2021 13:47:03

4K+ Views

There are three ways by which the values of structure can be transferred from one function to another. They are as follows −Passing individual members as arguments to function.Passing entire structure as an argument to function.Passing the address of structure as an argument to function.Now let’s see how to Pass an entire structure as an argument to function.Name of the structure variable is given as argument in function call.It is collected in another structure variable in function header.The disadvantage is that a copy of an entire structure is created again by wasting the memory.ExampleThe following program shows how to pass ... Read More

How to pass the individual members as arguments to function using structure elements?

Bhanu Priya
Updated on 11-Mar-2021 14:02:48

2K+ Views

There are three ways by which the values of structure can be transferred from one function to another. They are as follows −Passing individual members as arguments to function.Passing entire structure as an argument to function.Passing the address of structure as an argument to function.Now let’s see how to pass an individual member of structure elements as arguments to function.Each member is passed as an argument in the function call.They are collected independently in ordinary variables in function header.ExampleGiven below is a C program to demonstrate passing individual arguments of structure to a function − Live Demo#include struct date{    int ... Read More

Explain the dynamic memory allocation of pointer to structure in C language

Bhanu Priya
Updated on 24-Mar-2021 13:44:57

5K+ Views

Pointer to structure holds the add of the entire structure.It is used to create complex data structures such as linked lists, trees, graphs and so on.The members of the structure can be accessed using a special operator called as an arrow operator ( -> ).DeclarationFollowing is the declaration for pointers to structures in C programming −struct tagname *ptr;For example: struct student *s;AccessingIt is explained below how to access the pointers to structures.Ptr-> membername;For example − s->sno, s->sname, s->marks;ExampleFollowing is a C program that explains the dynamic memory allocation of structure in C programming − Live Demo#include #include struct person ... Read More

Explain the concept of an array within a structure in C programming

Bhanu Priya
Updated on 19-Mar-2021 10:47:59

5K+ Views

An array of structure in C programming is a collection of different datatype variables, grouped together under a single name.General form of structure declarationThe structural declaration is as follows −struct tagname{    datatype member1;    datatype member2;    datatype member n; };Here, struct is the keyword.tagname specifies the name of structure.member1, member2 specifies the data items that make up structure.ExampleThe following example shows the usage of array within a structure in C programming −struct book{    int pages;    char author [30];    float price; };ExampleFollowing is the C program to demonstrate the use of an array within a structure ... Read More

C program demonstrating the concepts of strings using Pointers

Bhanu Priya
Updated on 19-Mar-2021 10:16:59

2K+ Views

An array of characters is called a string.DeclarationThe syntax for declaring an array is as follows −char stringname [size];For example − char string[50]; string of length 50 charactersInitializationUsing single character constant −char string[10] = { ‘H’, ‘e’, ‘l’, ‘l’, ‘o’ ,‘\0’}Using string constants −char string[10] = "Hello":;Accessing − There is a control string "%s" used for accessing the string till it encounters ‘\0’.Now, let us understand what are the arrays of pointers in C programming language.Arrays of pointers: (to strings)It is an array whose elements are ptrs to the base add of the string.It is declared and initialized as follows ... Read More

What is strstr() Function in C language?

Bhanu Priya
Updated on 19-Mar-2021 10:03:30

894 Views

The C library function char *strstr(const char *haystack, const char *needle) function finds the first occurrence of the substring needle in the string haystack. The terminating '\0' characters are not compared.An array of characters is called a string.DeclarationThe syntax for declaring an array is as follows −char stringname [size];For example − char string[50]; string of length 50 charactersInitializationUsing single character constant −char string[10] = { ‘H’, ‘e’, ‘l’, ‘l’, ‘o’ ,‘\0’}Using string constants −char string[10] = "Hello":;Accessing − There is a control string "%s" used for accessing the string till it encounters ‘\0’.The strstr() FunctionIt is used to search whether ... Read More

What is strncmp() Function in C language?

Bhanu Priya
Updated on 19-Mar-2021 10:00:39

3K+ Views

The C library function int strncmp(const char *str1, const char *str2, size_t n) compares at most the first n bytes of str1 and str2.An array of characters is called a string.DeclarationThe syntax for declaring an array is as follows −char stringname [size];For example − char string[50]; string of length 50 charactersInitializationUsing single character constant −char string[10] = { ‘H’, ‘e’, ‘l’, ‘l’, ‘o’ ,‘\0’}Using string constants −char string[10] = "Hello":;Accessing − There is a control string "%s" used for accessing the string till it encounters ‘\0’.The strncmp ( ) FunctionThis function is used for comparing first ‘n’ characters of 2 ... Read More

What is strcmp() Function in C language?

Bhanu Priya
Updated on 19-Mar-2021 09:57:34

671 Views

The C library function int strcmp(const char *str1, const char *str2) compares the string pointed to, by str1 to the string pointed to by str2.An array of characters is called a string.DeclarationFollowing is the declaration for an array −char stringname [size];For example − char string[50]; string of length 50 charactersInitializationUsing single character constant −char string[10] = { ‘H’, ‘e’, ‘l’, ‘l’, ‘o’ ,‘\0’}Using string constants −char string[10] = "Hello":;Accessing − There is a control string "%s" used for accessing the string till it encounters ‘\0’.The strcmp() functionThis function compares two strings.It returns the ASCII difference of the first two non ... Read More

What is strncat() Function in C language?

Bhanu Priya
Updated on 19-Mar-2021 09:53:42

1K+ Views

The C library function char *strncat(char *dest, const char *src, size_t n) appends the string pointed to by src to the end of the string pointed to by dest up to n characters long.An array of characters is called a string.DeclarationFollowing is the declaration for an array −char stringname [size];For example: char string[50]; string of length 50 charactersInitializationUsing single character constant −char string[10] = { ‘H’, ‘e’, ‘l’, ‘l’, ‘o’ ,‘\0’}Using string constants −char string[10] = "Hello":;Accessing − There is a control string "%s" used for accessing the string till it encounters ‘\0’.The strncat( ) functionThis is used for combining ... Read More

Advertisements