Server Side Programming Articles - Page 1233 of 2650

How to assign a pointer to function using C program?

Bhanu Priya
Updated on 09-Mar-2021 08:32:14

753 Views

Pointer to functionIt holds the base address of function definition in memory.Declarationdatatype (*pointername) ();The name of the function itself specifies the base address of the function. So, initialization is done using function name.For example, int (*p) (); p = display; //display () is a function that is defined.Example 1We shall see a program for calling a function using pointer to function −#include main (){    int (*p) (); //declaring pointer to function    clrscr ();    p = display;    *(p) (); //calling pointer to function    getch (); } display (){ //called function present at pointer location    printf(“Hello”); ... Read More

Explain the concept of Array of Pointer and Pointer to Pointer in C programming

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

2K+ Views

Array Of PointersJust like any other data type, we can also declare a pointer array.Declarationdatatype *pointername [size];For example, int *p[5]; //It represents an array of pointers that can hold 5 integer element addressesInitializationThe ‘&’ is used for initializationFor example,int a[3] = {10,20,30}; int *p[3], i; for (i=0; i

Explain the concepts of Pointers and arrays in C language

Bhanu Priya
Updated on 06-Dec-2024 15:26:29

3K+ Views

Pointers and Arrays A pointer in C is a variable that stores the address of another variable, which can be of any type(char, int, function). In a 32-bit system, the size of the pointer is 2 bytes. An array is a collection of similar data items stored in contiguous memory locations. In C, arrays can store various data types(char, int, double float) as well as specific types(pointer structures). For example, if we need to represent an array of 5 elements we need to create it as - int a [5] = {10, 20, 30, 40, 50}; ... Read More

Explain Arithmetic operations using pointers in C language?

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

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

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

594 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

374 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?

Sindhura Repala
Updated on 21-Jan-2025 16:13:15

31K+ Views

Functions are categorized bases on the presence or absences of arguments and whether they return a value. A user-defined function is one that is defined by the user when writing any program, as opposed to library functions that have predefined definitions. To meet specific requirements, the user must develop their own functions. Such functions must be properly defined by the user. A function is a block of code designed to perform a specific task. It is written once and can be reused multiple times as needed by the programmer. ... Read More

What are the different types of functions in C Programming?

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

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

Advertisements