You must Sign In to post a response.
  • Category: Software

    Query about computer software

    Want to know about pointers in C language? Go through the answers.

    Why pointers of c++ language is doing important role at the time of making any software?
  • #140482
    Pointers are variables/data types which stores the addresses/data and also can be null. Types of pointers are like Integral, Floating and void.

    Integral pointers are capable of handling the whole numbers.
    Floating pointers are the one specifying values that may have fractional parts.
    Void pointers describes an empty set of values and it is primarily to declare functions that return no values or to declare generic pointers to arbitrarily typed data

    Like in Java these pointers help us to get the access to the data and use it in our script. With Integral and floating we can perform the arithmetic operations which is used widely.

    Some times peace is better than being Right!!!

  • #140483
    Moving this to AE section.
    Live life Kingsize!

  • #140485
    It's easy to understand roles of pointers in C. Variables hold the data in memory. And pointers are pointing to space where variables are holding the data. These pointers come in different forms - integer, float and void. Integer pointer have whole numbers and no decimal points. In case of float pointer, it contains the numbers with decimal pointer. As for the void t does not have the return value.

    C is less likely to be used for desktop level software. C and C++ are used on creating system level software. Here you need pointers to free up memory space. And also for things like clearing ROM or operating system cache. So this has it's use on system level software.

  • #140515
    pointers are very essential dynamic memory location for data structures efficient handling for large amount of data. If pointers are not there then you should locate all the data globally. pointer is very useful tool in c++ .Basically pointer is variable which holds memory address than a value.
    For Eg int myVariable; ---this will hold a variable which has integer value.
    int *my pointer; --this will hold portion of memory which has the address of _another_ portion of memory of an integer value.

    *myPointer=myVariable ;--- this means that a pointer now holds an memory location for variable.
    In programming language pointers are always used as a reference to another variable. Pointers cannot be used for referencing existing variable.

  • #140581
    Pointers in C++ act like an address of a particular value. For example if you want to store something then you need some variable and to define the type of variable you need data type so what will give is the address of the value stored in the variable of the particular data type. consider the following:

    int cool = 5;

    now here int is the data type and 5 is the value. 5 get to store in variable cool but to refer the value of the variable without referring to direct variable we need address of the variable suppose address of the variable is 5000. so here 5000 will give me value 5 if address of the variable is 5000. hence pointer plays indirect roles to make any software because programming even a single bit of computer information is stored in a memory and to retrieve that information the pointer is very essential.

  • #141989
    Before going to concept of pointer it is necessary to distinguish between normal variable and pointer variable. Normal variable always stores value and pointer variable always store address of appropriate type variable. In pointer terminology two operators are used namely & operator (ampersand) and * operator (asterisk). Here & operator means address of operator and * operator means value at address operator. So pointer is also known as reference variable as it refers the address of a variable and indirectly points to that variable.

    Syntax for declaring pointer variable is as follows
    data type * pointer variable name;

    example of declaring pointer variable is as follows
    int * p;

    It is necessary to understand what is the meaning of above statement. It means p is a pointer variable which is able to hold address of an integer variable only and not the address of any other type variable.
    int x=635;
    int * p;
    p=&x; This statement is valid because p is an integer pointer and it is able to hold address of integer x.

    Real appeal of pointer is that once we get the address of a variable, we can operate indirectly on the variable whose address is hold by the pointer.
    So if we write *p=670; then it means that value of x now becomes 670.

    Real use of pointer comes into picture when we need to pass arguments to function and want to access the actual parameters inside the function. In this case we pass parameters by reference i.e. by using pointer.
    Following program shows use of pointer in function.

    void main(void)
    void swap(int * , int *);
    int a,b;
    printf("Enter any two numbers\n");
    printf("\nBefore swapping value of a is %d and value of b is %d",a,b);
    printf("\nAfter swapping value of a is %d and value of b is %d",a,b);

    void swap(int * x, int * y)
    int temp;
    temp= *x;
    *x = *y;
    *y = temp;
    Here in above example function pass address of a and b, not values. So that in function re declaration pointer x and y are used to receive addresses of a and b respectively. Inside the function when changes are made in *x and *y, it ultimately reflects in calling function. So though function does not return any value still it swaps value of a and b in main function.

    Especially in character array, when it not known in advance what will be the size of an character array. In such case character pointer variable is used to store required string with exactly required space and hence avoid the declaration such as char name[30], where 30 may be more that required or may be less that required space.
    suppose we declare a statement like

    char * name ;
    Then by using

    scanf("%s",name); we can read a string of any length without wastage of memory space.

    Pointers may be used for structure, class also. It means we can use pointer on derived data types also.
    In general we can assign pointer to every entity that has address.

  • Sign In to post your comments