Found 1401 Articles for C

What are pointers to structures in C language?

Bhanu Priya
Updated on 14-Sep-2023 02:44:23

26K+ 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;Example ProgramThe following program shows the usage of pointers to structures −#include struct student{    int sno;    char sname[30];   ... Read More

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

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

4K+ 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

Explain the array of structures in C language

Bhanu Priya
Updated on 06-Sep-2023 12:57:58

43K+ 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 name of structure    member1, member2 specifies the data items that make up structure.ExampleThe following example shows the usage of array of structures in C programming −struct book{    int pages;    char author [30];    float price; };Array of structuresThe most common use of structure in C programming is an ... Read More

C program demonstrating the concepts of strings using Pointers

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

1K+ 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

788 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

592 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

What is strcat() Function in C language?

Bhanu Priya
Updated on 19-Mar-2021 09:52:40

1K+ Views

The C library function char *strcat(char *dest, const char *src) appends the string pointed to by src to the end of the string pointed to by dest.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 strcat( ) functionThis is used for combining or concatenating two strings.The length of ... Read More

What is strcpy() Function in C language?

Bhanu Priya
Updated on 19-Mar-2021 09:49:39

632 Views

The C library function char *strcpy(char *dest, const char *src) copies the string pointed to, by src to dest.An array of characters is called a string.DeclarationFollowing is the declaration for an arraychar 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 strcpy ( ) functionThis function is used for copying source string into destination string.The length of the destination string is greater than ... Read More

Advertisements