Found 1401 Articles for C

Explain the concepts of Pointers and arrays in C language

Bhanu Priya
Updated on 09-Mar-2021 08:17:06

3K+ Views

Pointers and arraysContinuous memory locations are allocated for all the elements of the array by the compiler.The base address is the location of the first element in the array.For example, int a [5] = {10, 20, 30, 40, 50};The five elements are stored as follows −If ‘p’ is declared as integer pointer, then the array ‘a’ can be pointed by the following assignment −p=a or p=&a[0];Each value of ‘a’ is accessed by using p++ to move from one element to another. When a pointer is incremented, its value is increased by the size of the datatype that it points to. ... Read More

Explain Arithmetic operations using pointers in C language?

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

1K+ 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;Arithmetic operations using pointersPointer variables can be used in expressions. For example, if pointer variables are properly declared and initialized then the following statements are valid.a) *p1 + *p2 b) *p1- *p2 c) *p1 * *p2 d) *p1/ *p2 Note: There must be a blank ... Read More

How to pass individual elements in an array as argument to function in C language?

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

2K+ Views

If individual elements are to be passed as arguments, then array elements along with their subscripts must be given in function call.To receive the elements, simple variables are used in function definition.Example 1#include main (){    void display (int, int);    int a[5], i;    clrscr();    printf (“enter 5 elements”);    for (i=0; i

How to pass entire array as an argument to a function in C language?

Bhanu Priya
Updated on 09-Mar-2021 08:08:41

910 Views

ArrayThe array is a group of related items that store with a common name. Following are the two ways of passing arrays as arguments to functions −sending entire array as argument to functionsending individual elements as argument to functionSending entire array as an argument to a functionTo send entire array as argument, just send the array name in the function call.To receive an array, it must be declared in the function header.Example 1#include main (){    void display (int a[5]);    int a[5], i;    clrscr();    printf ("enter 5 elements");    for (i=0; i

What are the scope rules to functions in C programming?

Bhanu Priya
Updated on 09-Mar-2021 08:03:16

384 Views

Local scopeLocal scope specifies that variables defined within the block are visible only in that block and invisible outside the block.Global scopeGlobal scope specifies that variables defined outside the block are visible up to end of the program.Example#include int r= 50; /* global area */ main (){    int p = 30;    printf (“p=%d, r=%d” p, r);    fun (); } fun (){    printf (“r=%d”, r); }Outputp =30, r = 50 r = 50Scope rules related to functionsA Function is a block of statements that performs a particular task.Variables that are declared within the body of a function ... Read More

What are the local and global scope rules in C language?

Bhanu Priya
Updated on 09-Mar-2021 07:27:45

249 Views

Global scopeGlobal scope specifies that variables defined outside the block are visible up to end of the program.Example#include int c= 30; /* global area */ main (){    int a = 10;    printf (“a=%d, c=%d” a, c);    fun (); } fun (){    printf (“c=%d”, c); }Outputa =10, c = 30 c = 30Local scopeLocal scope specifies that variables defined within the block are visible only in that block and invisible outside the block.Variables declared in a block or function (local) are accessible within that block and does not exist outside it.Example#include main (){    int i = ... Read More

What are the different categories of functions in C Programming?

Bhanu Priya
Updated on 21-Oct-2023 13:25:40

25K+ Views

Depending on whether arguments are present or not and whether a value is returned or not, functions are categorized into − Functions without arguments and without return values Functions without arguments and with return values Functions with arguments and without return values Functions with arguments and with return values Functions without arguments and without return values Example ... Read More

What are the different types of functions in C Programming?

Bhanu Priya
Updated on 09-Mar-2021 07:06:23

13K+ Views

Functions are broadly classified into two types which are as follows −predefined functionsuser defined functionsPredefined (or) library functionsThese functions are already defined in the system libraries.Programmer can reuse the existing code in the system libraries which is helpful to write error free code.User must be aware of syntax of the function.For instance, sqrt() function is available in math.h library and its usage is y= sqrt (x), where x= number must be positive.If x value is 25, i.e., y = sqrt (25) then ‘y’ = 5.In the same way, printf() is available in stdio.h library and clrscr() is available in conio.h ... Read More

How to write a C program to find the roots of a quadratic equation?

Bhanu Priya
Updated on 01-Sep-2023 02:10:09

111K+ Views

ProblemApplying the software development method to solve any problem in C Language.SolutionFind roots of a quadratic equation, ax2+bx+c.There will be 2 roots for given quadratic equation.AnalysisInput − a, b, c valuesOutput − r1, r2 valuesProcedure$r_{1}=\frac{-b+\sqrt{b^2-4ac}}{2a}$$r_{2}=\frac{-b-\sqrt{b^2-4ac}}{2a}$Design (Algorithm)StartRead a, b, c valuesCompute d = b2 4acif d > 0 thenr1 = b+ sqrt (d)/(2*a)r2 = b sqrt(d)/(2*a)Otherwise if d = 0 thencompute r1 = -b/2a, r2=-b/2aprint r1, r2 valuesOtherwise if d < 0 then print roots are imaginaryStopImplementation Code# include # include int main () { float a, b, c, r1, r2, d; ... Read More

Convert vowels from upper to lower or lower to upper using C program

Bhanu Priya
Updated on 24-Mar-2021 14:29:19

1K+ Views

An array of characters is called a string.DeclarationFollowing is the declaration for an array −char stringname [size];For example − char a[50]; string of length 50 charactersInitializationUsing single character constant −char a[10] = { ‘H’, ‘e’, ‘l’, ‘l’, ‘o’ ,‘\0’}Using string constants −char a[10] = "Hello":;AccessingThere is a control string "%s" used for accessing the string till it encounters ‘\0’.The logic used to convert vowels from upper to lower or lower to upper is −for(i=0;string[i]!='\0';i++){    if(string[i]=='a'||string[i]=='e'||string[i]=='i'||string[i]=='o'||string[i]=='u'){       string[i]=toupper(string[i]);    } } printf("The result string with converted vowels is : "); puts(string);ProgramFollowing is the C program using conversion functions ... Read More

Advertisements