Found 1401 Articles for C

What is strspn() Function in C language?

Bhanu Priya
Updated on 19-Mar-2021 09:47:21

225 Views

The C library function size_t strspn(const char *str1, const char *str2) calculates the length of the initial segment of str1 which consists entirely of characters in 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 Strspn() functionThis function search for specified string in the given string and returns ... Read More

What is strcoll() Function in C language?

Bhanu Priya
Updated on 19-Mar-2021 08:38:23

368 Views

The C library function int strcoll(const char *str1, const char *str2) compares string str1 to str2. The result is dependent on the LC_COLLATE setting of the location.An array of characters is called a stringDeclarationGiven below is the declaration of 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 Strcoll() FunctionThis function is same as strcmp() function, it compares two strings ... Read More

What is strlen function in C language?

Bhanu Priya
Updated on 17-Mar-2021 10:43:15

539 Views

The C library function size_t strlen(const char *str) computes the length of the string str up to, but not including the terminating null character.An array of characters is called a string.DeclarationGiven below is the declaration of an array −char stringname [size];For example − char a[50]; string of length 50 charactersInitializationUsing single character constant −char a[10] = { ‘H’, ‘e’, ‘l’, ‘l’, ‘o’ ,‘\0’}Using string constants −char a[10] = "Hello":;Accessing − There is a control string "%s" used for accessing the string till it encounters ‘\0’The strlen ( ) functionThis function gives the length of the string, i.e., the number of ... Read More

What is pass by reference in C language?

Bhanu Priya
Updated on 17-Mar-2021 10:41:14

1K+ Views

Pass by reference in C programming language is the addresses which are sent as arguments.AlgorithmAn algorithm is given below to explain the working of pass by value in C language.START Step 1: Declare a function with pointer variables that to be called. Step 2: Declare variables a, b. Step 3: Enter two variables a, b at runtime. Step 4: Calling function with pass by reference. jump to step 6 Step 5: Print the result values a, b. Step 6: Called function swap having address as arguments.    i. Declare temp variable    ii. Temp=*a    iii. *a=*b    iv. *b=temp ... Read More

What is pass by value in C language?

Bhanu Priya
Updated on 17-Mar-2021 10:39:59

3K+ Views

Pass by value is termed as the values which are sent as arguments in C programming language.AlgorithmAn algorithm is given below to explain the working of pass by value in C language.START Step 1: Declare a function that to be called. Step 2: Declare variables. Step 3: Enter two variables a, b at runtime. Step 4: calling function jump to step 6. Step 5: Print the result values a, b. Step 6: Called function swap.    i. Declare temp variable    ii. Temp=a    iii. a=b    iv. b=temp STOPExampleGiven below is the C program to swap the two numbers ... Read More

What is Realloc in C language?

Bhanu Priya
Updated on 17-Mar-2021 10:38:43

534 Views

The C library memory allocation function void *realloc(void *ptr, size_t size) attempts to resize the memory block pointed to by ptr that was previously allocated with a call to malloc or calloc.Memory allocation FunctionsMemory can be allocated in two ways as explained below −Once memory is allocated at compile time, it cannot be changed during execution. There will be a problem of either insufficiency or else wastage of memory.The solution is to create memory dynamically i.e. as per the requirement of the user during execution of program.The standard library functions which are used for dynamic memory management are as follows ... Read More

What is Calloc in C language?

Bhanu Priya
Updated on 17-Mar-2021 10:37:07

560 Views

The C library memory allocation function void *calloc(size_t nitems, size_t size) allocates the requested memory and returns a pointer to it.The difference in malloc and calloc is that malloc does not set the memory to zero, whereas, calloc sets the allocated memory to zero.Memory allocation FunctionsMemory can be allocated in two ways as explained below −Once memory is allocated at compile time, it cannot be changed during execution. There will be a problem of either insufficiency or else wastage of memory.The solution is to create memory dynamically i.e. as per the requirement of the user during execution of program.The standard ... Read More

What is malloc in C language?

Bhanu Priya
Updated on 17-Mar-2021 10:34:28

5K+ Views

The C library memory allocation function void *malloc(size_t size) allocates the requested memory and returns a pointer to it.Memory allocation FunctionsMemory can be allocated in two ways as explained below −Once memory is allocated at compile time, it cannot be changed during execution. There will be a problem of either insufficiency or else wastage of memory.The solution is to create memory dynamically i.e. as per the requirement of the user during execution of program.The standard library functions which are used for dynamic memory management are as follows −malloc ( )calloc ( )realloc ( )free ( )The Malloc() FunctionThis function is ... Read More

What is void pointer in C language?

Bhanu Priya
Updated on 17-Mar-2021 10:33:07

669 Views

It is a pointer that can hold the address of any datatype variable (or) can point to any datatype variable.DeclarationThe declaration for void pointer is as follows −void *pointername;For example − void *vp;Accessing − Type cast operator is used for accessing the value of a variable through its pointer.SyntaxThe syntax for void pointer is given below −* ( (type cast) void pointer)Example 1int i=10; void *vp; vp = &i; printf ("%d", * ((int*) vp)); // int * type castExampleFollowing is the C program for void pointer − Live Demo#include main ( ){    int i =10;    float f = 5.34; ... Read More

Explain array of pointers in C programming language

Bhanu Priya
Updated on 17-Mar-2021 10:30:47

13K+ Views

Pointer is a variable that stores the address of another variable.FeaturesPointer saves the memory space.Execution time of pointer is faster because of direct access to memory location.With the help of pointers, the memory is accessed efficiently, i.e., memory is allocated and deallocated dynamically.Pointers are used with data structures.Pointer declaration and initializationConsider the following statement −int qty = 179;In memory, the variable can be represented as follows −Declaring a pointerIt means ‘p’ is a pointer variable, which holds the address of another integer variable, as shown below −Int *p;Initialization of a pointerAddress operator (&) is used to initialise a pointer variable.For ... Read More

Advertisements