Double pointer or pointer to pointer is a variable that holds the address of another pointer.Following is the declaration for a pointer to a pointer −datatype ** pointer_name;For example, int **p; p is a pointer to pointerInitialization − ‘&’ is used for initialization.For example, int a = 10; int *p; int **q; p = &a;Accessing − Indirection operator (*) is used for accessing.ExampleFollowing is the C program for the pointer to pointer − Live Demo#include main ( ){ int A = 10; int *p; int **q; p = &A; q = &p; printf("A =%d", A); ... Read More
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
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
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
The preprocessor is a program that sends the source code before it passes through the compiler. It operates under preprocessor directives which begin with the symbol #.TypesThe three types of preprocessor commands are as follows −Macro substitution directives.File inclusion directives.Compiler control directives.Macro substitution directivesIt replaces every occurrence of an identifier by a predefined string.The syntax for defining a macro substitution directive is as follows −# define identifier stringFor example, #define PI 3.1415 #define f(x) x *x #undef PIExampleFollowing is the C program for the macro substitution directive −#define wait getch( ) main ( ){ ... Read More
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
Type qualifiers add special attributes to existing datatypes in C programming language.There are three type qualifiers in C language and constant type qualifier is explained below −ConstThere are three types of constants, which are as follows −Literal constantsDefined constantsMemory constantsLiteral constants − These are the unnamed constants that are used to specify data.For example, a=b+7 //Here ‘7’ is literal constant.Defined constants − These constants use the preprocessor command ‘define" with #For example, #define PI 3.1415Memory constants − These constants use ‘C’ qualifier ‘const’, which indicates that the data cannot be changed.The syntax is as follows −const type identifier = valueFor ... Read More
ProblemHow to convert a decimal number to a binary number by using the function in the C programming language?SolutionIn this program, we are calling a function to binary in main(). The called function to binary will perform actual conversion.The logic we are using is called function to convert decimal number to binary number is as follows −while(dno != 0){ rem = dno % 2; bno = bno + rem * f; f = f * 10; dno = dno / 2; }Finally, it returns the binary number to the main program.ExampleFollowing is the C program to ... Read More
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
The logic to print a one-month calendar is as follows −for(i=1;i
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP