Found 1452 Articles for C

Differentiate between int main and int main(void) function in C

Bhanu Priya
Updated on 08-Dec-2023 14:00:41

14K+ Views

int main represents that the function returns some integer even ‘0’ at the end of the program execution. ‘0’ represents the successful execution of a program.The syntax of int main is as follows − int main(){    ---    ---    return 0; } int main(void) represents that the function takes NO argument. Suppose, if we don’t keep void in the bracket, the function will take any number of arguments.The syntax of int main(void) is as follows − int main(void){    ---    ---    return 0; } Actually, both seem to be the same but, ... Read More

What are string searching functions in C language?

Bhanu Priya
Updated on 02-Sep-2021 13:34:32

842 Views

The library also provides several string searching functions, which are as follows −char *strchr (const char *string, intc);Find first occurrence of character c in string.char "strrchr (const char "string, intc);Find last occurrence of character c in string.char *strpbrk (const char *s1, const char *s2);returns a pointer to the first occurrence in string s1 of any character from string s2, or a null pointer if no character from s2 exists in s1.size_t strspn (const char *s1, const char *s2);returns the number of characters at the beginning of s1 that match s2.size_t strcspn (const char *51, const char *s2);returns the number of ... Read More

What are memory operations in C language?

Bhanu Priya
Updated on 02-Sep-2021 13:20:50

696 Views

The library #include contains the basic memory operations. Although not strictly string functions, the functions are prototyped in #include .These memory operations are as follows −void *memchr (void *s, int c, size_t n);Search for a character in a buffer.int memcmp (void *s1, void *s2, size_t n);Compare two buffers.void *memcpy (void *dest, void *src, size_t n);Copy one buffer into another.void *memmove (void *dest, void *src, size_t n);Move a number of bytes from one buffer to another.void *memset (void *s, int c, size_t n);Set all bytes of a buffer to a given character.Note that in all case to bytes of memory ... Read More

What is conditional compilation in C language?

Bhanu Priya
Updated on 02-Sep-2021 13:19:11

9K+ Views

In C programming language, several directives control the selective compilation of portions of the program code. They are as follows −#if#else#elif#endifThe general form of #if is as follows −#if constant_expression    statement sequence #endif#else works much like the C keyword else.#elif means "else if" and establishes an if else-if compilation chain.Amongst other things, #if provides an alternative method of "commenting out" code.For example, #if 0    printf("#d", total); #endifHere, the compiler will ignore printf("#d", total);#ifdef and #ifndef#ifdef means "if defined", and is terminated by an #endif.#indef means "if not defined".#undef#undef removes a previously defined definition.#line#line changes the contents of __LINE__ ... Read More

Differentiate between array and structures in C

Bhanu Priya
Updated on 02-Sep-2021 13:17:30

206 Views

The major differences between an array and a structure in C programming language are as follows −ArraysStructuresAn array is a single entity representing a collection of data items of same data types.A structure is a single entity representing a collection of data items of different data types.Individual entries in an array are called elements.Individual entries in a structure are called members.An array declaration reserves enough memory space for its elements.The structure definition reserves enough memory space for its members.There is no keyword to represent arrays but the square braces [] preceding the variable name tells us that we are dealing ... Read More

C program to store inventory system using structures

Bhanu Priya
Updated on 01-Sep-2021 13:18:41

6K+ Views

Structure is a collection of different datatype variables, grouped together under a single name.Features of structureThe features of structure in the C programming language are as follows −It is possible to copy the contents of all the structure elements of different datatypes to another structure variable of its type by using an assignment operator.For handling the complex datatypes, it is better to create structure within another structure, which is called nested structures.It is possible to pass an entire structure, individual elements of structure and an address of structure to a function.It is possible to create structure pointers.ProgramFollowing is the C ... Read More

C program to sort names in alphabetical order using structures

Bhanu Priya
Updated on 02-Sep-2023 13:54:56

4K+ Views

Structure is a collection of different datatype variables, grouped together under a single name.Features of structureThe features of structure in the C programming language are as follows −It is possible to copy the contents of all the structure elements of different datatypes to another structure variable of its type by using an assignment operator.For handling the complex datatypes, it is better to create structure within another structure, which is called nested structures.It is possible to pass an entire structure, individual elements of structure and an address of structure to a function.It is possible to create structure pointers.Declaration and initialization of ... Read More

C program to compare if the two matrices are equal or not

Bhanu Priya
Updated on 01-Sep-2021 13:13:28

2K+ Views

The user has to enter the order of two matrices and elements of two matrices. Then, these two matrix are compared.If both matrix elements and size are equal, then it displays that the two matrices are equal.If size of matrix is equal but the elements are not equal, then it displays that the matrix can be compared but is not equal.If the size and elements are not matched, then it displays that the matrices cannot be compared.ProgramFollowing is the C program to compare if the two matrices are equal or not −#include #include main(){    int A[10][10], B[10][10]; ... Read More

C program to sort all columns and rows of matrix

Bhanu Priya
Updated on 01-Sep-2021 13:10:15

4K+ Views

ProblemWrite a code to sort all the rows of matrix in an ascending order and all columns in the descending order. The size of matrix and elements of matrix are given by user at runtime.SolutionThe solution to sort all the rows of matrix in an ascending order and all columns in the descending order in the C programming language is explained below −The logic used to sort the rows in an ascending order is as follows −for (i=0;i

C program to interchange the diagonal elements in given matrix

Bhanu Priya
Updated on 01-Sep-2021 13:07:55

804 Views

ProblemWe need to write a code to interchange the main diagonal elements with the secondary diagonal elements. The size of the matrix is given at runtime.If the size of matrix m and n values are not equal, then it prints that the given matrix is not a square.Only a square matrix can interchange the main diagonal elements and can interchange with the secondary diagonal elements.SolutionThe solution to write a C program to interchange the diagonal elements in given matrix is as follows −The logic to interchange the diagonal elements is explained below −for (i=0;i

Previous 1 ... 5 6 7 8 9 ... 146 Next
Advertisements