Found 1339 Articles for C

Given an example of C pointer addition and subtraction

Bhanu Priya
Updated on 08-Mar-2021 06:45:44

3K+ Views

Pointers have many but easy concepts and they are very important to C programming.Two of the arithmetic pointer concepts are explained below, which are C pointer addition and subtraction respectively.C pointer additionC pointer addition refers to adding a value to the pointer variable.The formula is as follows −new_address= current_address + (number * size_of(data type))ExampleFollowing is the C program for C pointer addition − Live Demo#include int main(){    int num=500;    int *ptr;//pointer to int    ptr=#//stores the address of number variable    printf("add of ptr is %u ", ptr);    ptr=ptr+7; //adding 7 to pointer variable    printf("after adding add ... Read More

What are the different types of pointers in C language?

Bhanu Priya
Updated on 12-Dec-2024 17:13:22

36K+ Views

A pointer is a variable that stores the address of another variable. The deceleration of a pointer is similar to that of a variable the only difference is while declaring a pointer we need to use "*". Following is the syntax to declare a pointer − type *variable_name; Similar to variables, pointers can be declared in different types. Following is an example − #Integer type pointer int *integer_pointer; #Character type pointer char *character_pointer; The following are the points to be noted − Pointers enable direct memory access and manipulation, which is crucial for ... Read More

Compute sum of all elements in 2 D array in C

Bhanu Priya
Updated on 08-Mar-2021 06:19:59

4K+ Views

ProblemCalculate the sum of all elements of a two-dimensional array by using run-time initialization.SolutionTwo-dimensional Array is used in situations where a table of values have to be stored (or) in matrices applicationsThe syntax is as follows −datatype array_ name [rowsize] [column size];For example, int a[4] [4];Number of elements in an array = rowsize *columnsize = 4*4 = 16ExampleFollowing is the C program to calculate the sum of all elements of a two-dimensional array by using run-time initialization − Live Demo#include void main(){    //Declaring array and variables//    int A[4][3], i, j, even=0, odd=0;    //Reading elements into the array//   ... Read More

C Program on two-dimensional array initialized at run time

Bhanu Priya
Updated on 08-Mar-2021 06:18:38

378 Views

ProblemCalculate the sum and product of all elements in an array by using the run-time compilation.SolutionA two-dimensional array is used in situations where a table of values have to be stored (or) in matrices applicationsThe syntax is as follows −datatype array_ name [rowsize] [column size];For example, int a[5] [5];Number of elements in array = rowsize *columnsize = 5*5 = 25ExampleFollowing is the C program to calculate the sum and product of all elements in an array by using the run-time compilation − Live Demo#include void main(){    //Declaring the array - run time//    int A[2][3], B[2][3], i, j, sum[i][j], product[i][j]; ... Read More

How to print the elements in a reverse order from an array in C?

Bhanu Priya
Updated on 08-Mar-2021 06:16:34

9K+ Views

Try to print the elements in reverse order by following an algorithm given below −Step1 − Declare an array of size 5Step 2 − Enter the 5 elements in memory using for loopStep 3 − Display elements in reverse orderBy decrementing for loopThe only logic is to reverse the elements is For loop −for(i=4;i>=0;i--){    //Displaying O/p//    printf("array[%d] :", i);    printf("%d", array[i]); }ExampleFollowing is the C program to reverse the elements − Live Demo#include void main(){    //Declaring the array - run time//    int array[5], i;    //Reading elements into the array//    printf("Enter elements into the array: ... Read More

Explain volatile and restrict type qualifiers in C with an example

Bhanu Priya
Updated on 08-Mar-2021 06:13:02

1K+ Views

Type qualifiers add special attributes to existing data types in C programming language.There are three type qualifiers in C language and volatile and restrict type qualifiers are explained below −VolatileA volatile type qualifier is used to tell the compiler that a variable is shared. That is, a variable may be referenced and changed by other programs (or) entities if it is declared as volatile.For example, volatile int x;RestrictThis is used only with pointers. It indicates that the pointer is only an initial way to access the deference data. It provides more help to the compiler for optimization.Example ProgramFollowing is the ... Read More

What are the C library functions?

Bhanu Priya
Updated on 25-Oct-2023 14:49:59

26K+ Views

Library functions are built-in functions that are grouped together and placed in a common location called library. Each function here performs a specific operation. We can use this library functions to get the pre-defined output. All C standard library functions are declared by using many header files. These library functions are created at the time of designing the compilers. We include the header files in our C program by using #include. Whenever the program is run and executed, the related files are included in the C program. Header File Functions Some of the header file functions are as follows − ... Read More

What are the limitations of array in C language?

Bhanu Priya
Updated on 13-Mar-2021 11:49:17

12K+ Views

Arrays are a kind of data structure that can store a fixed-size sequential collection of elements of the same type.An array is used to store a collection of data, but it is often more useful to think of an array as a collection of variables of the same type.LimitationsThe limitations of an array are explained below −An array which is formed will be homogeneous. That is, in an integer array only integer values can be stored, while in a float array only floating value and character array can have only characters. Thus, no array can have values of two data ... Read More

Explain top-down design and structure chart of function in C language

Bhanu Priya
Updated on 13-Mar-2021 11:43:10

2K+ Views

A function is a self-contained block that carries out a specific well defined task.Advantages of functions in C language include −Reusability.The length of the program can be reduced.It is easy to locate and find any faulty function.It facilitates top-down modular programming.Top down design and structure chartsIt is a problem solving method in which a complex problem is solved by splitting into sub problems.Structure chart is a documentation tool that shows the relationships among the sub problems of a problem.The splitting of a problem into its related sub problems is the process of refining an algorithm. For example, performing arithmetic operations ... Read More

How floats are stored in C compiler?

Bhanu Priya
Updated on 13-Mar-2021 11:41:56

853 Views

In C programming language, float is a short term for floating point.Floating point numbers are generally represented in the form of Institute of Electrical and Electronics Engineers (IEEE) format.The IEEE format uses a sign bit, a mantissa and an exponent for representing the power of 2.The sign bit denotes the sign of the number: a 0 represents a positive value and a 1 denotes a negative value.The mantissa represented in binary after converting into its normalized form. After normalization mantissa, the most significant digit is always 1.The exponent is an integer stored in unsigned binary format after adding a positive ... Read More

Advertisements