Found 1339 Articles for C

What is void pointer in C language?

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

898 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

14K+ 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

Explain pointers and one-dimensional array in C language

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

8K+ Views

Pointer is a variable that stores the address of another variable.FeaturesThe features of pointer are explained below −Pointer saves the memory space.Execution time of pointer is faster because of direct access to the 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, initialization and accessingConsider 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 mentioned in the statement below −Int *p;Initialization ... Read More

How to send individual elements as an argument in C language?

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

203 Views

The array is a group of related items that is stored with a common name.Declaring arrayThe syntax used 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 initializationRuntime initializationAn 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 argument to function.Sending the individual elements ... Read More

Explain the scope rules related to the statement blocks in C language

Bhanu Priya
Updated on 15-Mar-2021 15:21:54

191 Views

The 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 statement blocks are given below −Block is enclosed in curly braces which consists of set of statements.Variables declared in a block are accessible and usable within that block and does not exist outside it.Example 1Following is the C program for scope rules related to statement blocks − Live Demo#include main ( ){    {       int i = 1;       printf ("%d", i);    }    {       int j=2;   ... Read More

What is a two-dimensional array in C language?

Bhanu Priya
Updated on 15-Mar-2021 15:11:52

4K+ Views

An array is a group of related items that store with a common name.SyntaxThe syntax is as follows for declaring an array −datatype array_name [size];Types of arraysArrays are broadly classified into three types. They are as follows −One – dimensional arraysTwo – dimensional arraysMulti – dimensional arraysInitializationAn array can be initialized in two ways, which are as follows −Compile time initialization.Runtime initialization.Two multidimensional arraysThese are used in situations where a table of values have to be stored (or) in matrices applications.SyntaxThe syntax is given below −datatype array_ name [rowsize] [column size];For example int a[5] [5];a[0][0]10a[0][1]20a[0][2]30a[1][0]40a[1][1]50a[1][2]60a[2][0]a[2][1]a[2][2]Following is the C Program for ... Read More

What is a one-dimensional array in C language?

Bhanu Priya
Updated on 15-Mar-2021 15:06:17

12K+ Views

An array is a group of related items that store with a common name.SyntaxThe syntax is as follows for declaring an array −datatype array_name [size];Types of arraysArrays are broadly classified into three types. They are as follows −One – dimensional arraysTwo – dimensional arraysMulti – dimensional arraysOne – dimensional arrayThe Syntax is as follows −datatype array name [size]For example, int a[5]InitializationAn array can be initialized in two ways, which are as follows −Compile time initializationRuntime initializationExampleFollowing is the C program on compile time initialization − Live Demo#include int main ( ){    int a[5] = {10, 20, 30, 40, 50};   ... Read More

C program to find Highest Common Factor (HCF) and Least Common Multiple (LCM)

Bhanu Priya
Updated on 15-Mar-2021 15:02:48

6K+ Views

First, let us learn how to find Highest Common Factor (HCF).Highest Common Factor (HCF)The greatest number divides each of the two or more numbers is called HCF or Highest Common Factor. It is also called as Greatest Common Measure(GCM) and Greatest Common Divisor(GCD).For example, What is the HCF of 12 and 16?Factors of 12 = 1, 2, 3, 4, 6, 12. Factors of 16=1, 2, 4, 8, 16Highest common factor (H.C.F) of 12 and 16 = 4.Least Common Multiple (LCM)For two integers x and y, denoted LCM(x, y), it is the smallest positive integer that is divisible by both x ... Read More

Explain nested switch case in C language

Bhanu Priya
Updated on 15-Mar-2021 14:59:55

998 Views

ProblemWrite a C program to check the entered password by the user is valid or not based on his/her ID using nested switch case.SolutionThe solution is explained below −In C language, we can write inner switch which is placed in an outer switch.The case values of the inner and outer switch can have common values.RulesAn expression executes to a result.Constants and unique values must be used for case labels.Case labels has to be end with a colon ( : ).A break keyword has to be included in each case.There can be only one default label.We can write nested multiple switch ... Read More

Explain else-if ladder statement in C language

Mandalika
Updated on 22-Feb-2021 06:44:48

14K+ Views

This is the most general way of writing a multi-way decision.SyntaxRefer the syntax given below −if (condition1) stmt1; else if (condition2) stmt2; - - - - - - - - - - else if (condition n) stmtn; else stmt x;AlgorithmRefer the algorithm given below −START Step 1: Declare int variables. Step 2: Read a, b, c, d values at runtime Step 3: i. if(a>b && a>c && a>d) Print a is largest ii.else if(b>c && b>a && b>d) Print b is largest iii. else if(c>d && c>a && c>b) Print c is largest iv. else print d is largest STOPExampleFollowing ... Read More

Advertisements