Found 1401 Articles for C

What do you mean by function return in C language?

Bhanu Priya
Updated on 08-Mar-2021 05:56:30

5K+ Views

A function is a self-contained block that carries out a specific task.The advantages of function in C language are as follows −ReusabilityThe length program can be reduced.It is easy to locate and isolate a wrong function.It facilitates top-down modular programming.ExampleFollowing is the C program for functions −#include /*Function prototypes*/ myfunc(); main(){    myfunc(); } /*Function Defination*/ myfunc(){    printf("Hello "); }Here, In calculations, we generally expect a function to return a value. But, it may or may not accept the arguments.This return value has a type int, float, char or anything else.Default type of function is integer.ExampleAnother program for the ... Read More

C Program to print the sum of boundary elements of a matrix

Bhanu Priya
Updated on 24-Mar-2021 14:28:37

5K+ Views

Given a matrix, we need to print the boundary elements of the matrix and display their sum.ExampleRefer the matrix given below −Given matrix1 2 3 4 5 6 7 8 9Boundary Matrix1 2 3 4   6 7 8 9Sum of boundary elements: 1 + 2 + 3 + 4 + 6 + 7 + 8 + 9 = 40The logic to find the sum of boundary matrix is as follows −for(i = 0; i

C program to calculate power of a given number

Bhanu Priya
Updated on 24-Mar-2021 14:14:46

16K+ Views

Take two integers from the user for base and exponent and calculate the power as explained below.ExampleConsider the following for writing a C program.Suppose base =3Exponent = 4Power=3*3*3*3AlgorithmFollow the algorithm given below −Step 1: Declare int and long variables. Step 2: Enter base value through console. Step 3: Enter exponent value through console. Step 4: While loop. Exponent !=0    i. Value *=base    ii. –exponent Step 5: Print the result.ExampleThe following program explains how to calculate power of given number in C language.#include int main(){    int base, exponent;    long value = 1;    printf("Enter a base value: ... Read More

C Program to find minimum occurrence of character in a string

Bhanu Priya
Updated on 24-Mar-2021 14:12:33

1K+ Views

An array of characters is called a string.DeclarationFollowing is the declaration 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’.Finding minimum occurrenceThe logic to find minimum occurrence of a character in a given string is as follows −for(i=0; i

C program to print array of pointers to strings and their address

Bhanu Priya
Updated on 19-Mar-2021 10:04:52

7K+ Views

First, 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 −char *a[ ] = {"one", "two", "three"};Here, a[0] is a pointer to the base add of string "one".         a[1] is a pointer to the base add of string "two".         a[2] is a pointer to the base add of string "three".AdvantagesThe advantages of array of pointers are explained below −Unlink the two dimensional array of characters, in ... Read More

What is strrev() Function in C language?

Bhanu Priya
Updated on 19-Mar-2021 10:01:46

3K+ 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’.The strrev( ) FunctionThis function is used for reversing a string.The reversed string is stored in the same string.SyntaxThe syntax for strrev() function is as follows −strrev (string)ExampleThe following program shows the usage of strrev() function.#include main ( ... Read More

What is strncpy() Function in C language?

Bhanu Priya
Updated on 19-Mar-2021 09:50:54

693 Views

The C library function char *strncpy(char *dest, const char *src, size_t n) copies up to n characters from the string pointed to, by src to dest. In a case where, the length of src is less than that of n, the remainder of dest will be padded with null bytes.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 ... Read More

Explain pointers and two-dimensional array in C language

Bhanu Priya
Updated on 17-Mar-2021 10:23:57

5K+ 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.Pointers and two dimensional arraysMemory allocation for a two-dimensional array is as follows −int a[3] [3] = {1, 2, 3, 4, 5, 6, 7, 8, 9};a[1] [2] = *(1234 + 1*3+2) = *(1234 + 3+2) = *(1234 + 5*4) // 4 is Scale factor = * (1234+20) = *(1254) a[1] [2] = 6ExampleFollowing ... Read More

How to send an entire array as an argument in C language?

Bhanu Priya
Updated on 17-Mar-2021 10:00:40

222 Views

An array is a group of related items that is stored with a common name.Declaring arrayThe syntax for declaring an array is as follows −datatype array_name [size];InitializationAn array can be initialized in two ways, which are as follows −Compile time initialization.Runtime initialization.An array can also be initialized at the time of declaration as follows −int a[5] = {100, 200, 300, 400, 500};FunctionA function is a self-contained block that carries out a specific well-defined task. The two ways of passing the arrays as arguments to functions are as follows −Sending an entire array as an argument to function.Sending the individual elements ... Read More

Explain scope rules related to the functions in C language

Bhanu Priya
Updated on 15-Mar-2021 15:22:35

445 Views

Scope rules are related to the following factors −Accessibility of a variables.Period of existence of a variable.Boundary of usage of variables.Scope rules related to functions are as followsFunction which is a self-contained block that performs a particular task.Variables that are declared within the function body are called local variables.These variables only exist inside the specific function that creates them. They are unknown to other functions and to the main functions too.The existence of local variables ends when the function completes its specific task and returns to the calling point.Example 1Following is the C program for scope rules related to functions ... Read More

Advertisements