Found 1401 Articles for C

Write a program to understand the concept of pointers in C language?

Bhanu Priya
Updated on 09-Mar-2021 08:42:01

344 Views

Pointer is a variable which stores the address of other variable.Features of PointersFollowing are the features of pointers −Saves the memory spaceExecution time is faster because of direct access to memory location.The memory is accessed efficiently with the pointer i.e. dynamically memory is allocated and deallocated.Pointers are used with data structures.Here is an example for search demonstration −We can access and print a particular character in a string by using pointers.Following example shows how to access the elements using pointer −Example Live Demo#include int main(){    char array[5] = "Tutorial", *ptr, i, *ptr1;    ptr = &array[1];    ptr1 = ptr ... Read More

Working with two-dimensional array at runtime in C programming

Bhanu Priya
Updated on 09-Mar-2021 08:40:45

1K+ Views

ProblemWrite a C program to calculate sum and product of all elements in two-dimensional array using run time compilation.SolutionRuntime compilation or initialization is also called as dynamic allocation. Allocation of memory at the time of execution (run time) is known as dynamic memory allocation.The functions calloc() and malloc() support allocating of dynamic memory.In this program, we will calculate the sum of all elements and product of all elements of two-dimensional array at run time.Logic for computing sum of all elements in 2D array −printf("Sum array is : "); for(i=0;i

What do you mean by Dynamic memory allocation in C programming?

Bhanu Priya
Updated on 09-Mar-2021 08:39:33

12K+ Views

Dynamic Memory AllocationAllocation of memory at the time of execution (run time) is known as dynamic memory allocation.The functions calloc() and malloc() support allocating of dynamic memory.Dynamic allocation of memory space is done by using these functions when value is returned by functions and assigned to pointer variables.In this case, variables get allocated only if your program unit gets active.It uses the data structure called heap for implementing dynamic allocation.There is memory reusability and memory can be freed when not required.It is more efficient.In this memory allocation scheme, execution is slower than static memory allocation.Here memory can be released at ... Read More

Finding even and odd numbers in a set of elements dynamically using C language

Bhanu Priya
Updated on 09-Mar-2021 08:31:18

1K+ Views

ProblemTo compute sum of even numbers and odd numbers in a set of elements using dynamic memory allocation functions.SolutionIn this program, we are trying to find even and odd numbers in a set of numbers.The logic used to find even numbers in a set elements is given below −for(i=0;i

Explain dynamic memory allocation in C with an example

Bhanu Priya
Updated on 09-Mar-2021 08:30:19

11K+ Views

ProblemFind the sum of n numbers entered by user using dynamically allocated memory using C programming.SolutionThe Dynamic memory allocation enables the C programmers to allocate memory at runtime.The different functions that we used to allocate memory dynamically at run time are −malloc () − allocates a block of memory in bytes at runtime.calloc () − allocating continuous blocks of memory at run time.realloc () − used for reduce (or) extend the allocated memory.free () − deallocates previously allocated memory space.Following C program is to display the elements and calculate sum of n numbers.Using dynamic memory allocation functions, we are trying ... Read More

Post and Pre incremented of arrays in C language

Bhanu Priya
Updated on 09-Mar-2021 08:28:40

4K+ Views

ProblemExplaining the array post and pre incremented concept with the help of C program.SolutionIncrement operator (++) −It is used to increment the value of a variable by 1There two types of increment operators − pre increment and post increment.Increment operator is placed before the operand in preincrement and the value is first incremented and then operation is performed on it.eg: z = ++a; a= a+1 z=aIncrement operator is placed after the operand in post increment and the value is incremented after the operation is performed.eg: z = a++; z=a a= a+1Let’s consider an example to access particular elements in memory ... Read More

Explain the concept of pointer accessing in C language

Bhanu Priya
Updated on 09-Mar-2021 08:27:22

4K+ Views

Pointer is a variable which stores the address of other variable.Pointer declaration, initialization and accessingConsider the following statement −int qty = 179;Declaring a pointerint *p;‘p’ is a pointer variable that holds the address of another integer variable.Initialization of a pointerAddress operator (&) is used to initialize a pointer variable.int qty = 175; int *p; p= &qty;Let’s consider an example how the pointer is useful in accessing the elements in an array of string.In this program, we are trying to access an element which is present at particular location. The location can be found by using an operation.By adding pre incremented ... Read More

Example program on Dynamic memory allocation in C language

Bhanu Priya
Updated on 09-Mar-2021 08:25:51

3K+ Views

ProblemFind out the maximum and minimum from an array using dynamic memory allocation in C.SolutionThe Dynamic memory allocation enables the C programmers to allocate memory at runtime.The different functions that we used to allocate memory dynamically at run time are −The malloc () − allocates a block of memory in bytes at runtime.The calloc () − allocates continuous blocks of memory at runtime.The realloc () − used to reduce (or) extend the allocated memory.The free () − deallocates previously allocated memory space.Finding maximum and minimum number in an array using dynamic memory allocationThe logic for finding maximum element in an ... Read More

Matrix row sum and column sum using C program

Bhanu Priya
Updated on 09-Mar-2021 08:21:57

3K+ Views

ProblemLet’s write a C program to compute the row sum and column sum of a 5 x 5 array using run time compilation.SolutionIn this program, we are entering the values of array which is of size 5X5 matrix during runtime in the console, with the help of for loops we are trying to add rows and columns.Logic for doing row sum is given below −for(i=0;i

How to print the numbers in different formats using C program?

Bhanu Priya
Updated on 09-Mar-2021 08:07:30

490 Views

ProblemWhat is the logic in C language to print the numbers in different formats like pyramid, right angle triangle?SolutionTo print the numbers or symbols in different model we can take the help of for loop in the code.Example1Following is the C program to print pyramid − Live Demo#include int main(){    int n;    printf("Enter number of lines: ");    scanf("%d", &n);    printf("");    // loop for line number of lines    for(int i = 1; i

Advertisements