confuse about the pointer, and its usage for c language programming

Viewed 46

I have just learned how to use the point, and very confused about why we need to use it. let me bring up an example:

#include <stdio.h>
int main(){

int a,b,*ptr;
a = 2;
ptr = &a;
*ptr = a;
b = *ptr // why not we assign the value of a to b directly (b = a;)
return (0);
}

above is one of example I saw on the video tutorial, I have not had any experience of using pointer. therefore I wonder why do we need it, can anyone show me the use of pointer? thank you

1 Answers

"can anyone show me the use of pointer?"

int main( int argc, char **argv ) ...

The 2nd parameter is a pointer to a (null terminated) array of pointers to char (recognised as being pointers to "null terminated strings".)

Conventionally, any C program's entry point is the function main() and most programs receive one or more parameters (as strings) when executed.

This is just one of many examples where you will encounter pointers in C source code.

Related