MAKAUT BTech CSE/IT Data Structure concepts

Answer:

Accessing some memory locations remotely:

A pointer variable may be used to access some memory location that has been allocated for some other variable within or outside of its scope.

The variables defined within a function (remember, main() is also a function), are alive and active within the function itself. The code within which a variable is alive is called the scope of the variable. Thus all variables created within a function (including the formal parameters) have local or function level scope. 

The local variable of one function can not be accessed from other functions by its name. But, we can access the memory location allocated for that variable using its address. Hence, we may use a pointer variable to access the local variable of some function from another function, if needed. This concept can be further applied to parameter passing while function calls, File Handling, the creation of Linked Lists, Trees, and many more problem domains.

Explanation

A variable.

Example:

The following code snippet shows how to use a pointer.

#include<stdio.h>

void print_x(int x){   // This function creates a new variable named x  
    x = 200; 
    printf("\n\nvalue of x is %d", x);
}

void print_x_using_pointer(int *p){
    printf("\n\nvalue of x is %d", *p);
}

int main(){
    int x = 100;
  
    print_x();  // This will print 200    
    print_x_using_pointer(int *p);  // This will print 100   
    
    return 0;
}

Related Question:

  1. What is “call by reference” in C language?
  2. What is the scope of any variable?
  3. What are the “actual parameter” and the “formal parameter”?
  4. What is the scope of the formal parameters?

0 Replies to “How pointers are used in Parameter Passing in C?

  1. В современном мире, где диплом является началом успешной карьеры в любом направлении, многие пытаются найти максимально простой путь получения качественного образования. Факт наличия официального документа трудно переоценить. Ведь диплом открывает дверь перед людьми, стремящимися вступить в профессиональное сообщество или учиться в ВУЗе.
    В данном контексте наша компания предлагает очень быстро получить любой необходимый документ. Вы сможете заказать диплом старого или нового образца, что становится выгодным решением для человека, который не смог закончить обучение или утратил документ. дипломы производятся аккуратно, с особым вниманием к мельчайшим элементам, чтобы в итоге получился продукт, 100% соответствующий оригиналу.
    Преимущество данного подхода заключается не только в том, что можно быстро получить диплом. Процесс организован удобно, с нашей поддержкой. Начиная от выбора нужного образца до консультации по заполнению личной информации и доставки по стране — все под полным контролем наших мастеров.
    Для тех, кто ищет быстрый способ получить требуемый документ, наша компания предлагает выгодное решение. Приобрести диплом – значит избежать продолжительного обучения и не теряя времени переходить к достижению личных целей: к поступлению в университет или к началу удачной карьеры.
    https://www.google.tn/url?q=https://rudiplomista.com
    https://images.google.com.ph/url?q=https://rudiplomista.com
    http://images.google.rw/url?q=https://premialnie-diplomik.com
    https://www.google.com.ai/url?q=https://rudiplomista.com
    https://images.google.no/url?q=https://premialnie-diplomik.com

Leave a Reply

Your email address will not be published. Required fields are marked *