Found 1401 Articles for C

Explain pointers and one-dimensional array in C language

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

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

127 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

103 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 multi-dimensional array in C language?

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

502 Views

An array is a group of related items that store with a common name.SyntaxThe syntax for declaring an array is as follows −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. They are mentioned below −Compile time initialization.Runtime initialization.Multi-dimensional array‘C’ allows arrays of 3 (or) more dimensions.The exact limit is determined by compiler.SyntaxThe syntax is as follows −datatype arrayname [size1] [size2] ----- [sizen];For example, For 3 – dimensional array −int a[3] [3] [3];No. of elements = 3*3*3 ... Read More

What is a two-dimensional array in C language?

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

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

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

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

776 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 switch statement in C language

Bhanu Priya
Updated on 15-Mar-2021 14:58:34

6K+ Views

It is used to select one among multiple decisions. ‘switch’ successively tests a value against a list of integers (or) character constant. When a match is found, the statement (or) statements associated with that value are executed.SyntaxThe syntax is given below −switch (expression){    case value1 : stmt1;       break;    case value2 : stmt2;       break;    - - - - - -    default : stmt – x; }AlgorithmRefer the algorithm given below −Step 1: Declare variables. Step 2: Read expression variable. Step 3: Switch(expression)    If value 1 is select : stmt 1 ... Read More

Explain else-if ladder statement in C language

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

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