Get the technologies, internet, technology news and more. You can know about technologies and you are at right place for knowing knowledge.

http://topadbid.com/k/2134816/
https://earnflies.com/1JFq

Wednesday, November 7, 2018

Pointers in C | C programming tutorial

Pointers in C | C programming tutorial: Here you can see about how pointers works in C programming and examples of pointers.

What is Pointers in C: Pointers are variables in C which holds address of another variable or pointers contains address of another variable. Pointers are used to access the memory and manipulate the other variable address.

Befor I start pointers, first we will know about what is memory location or memory address. In C language when we declare a variable it assigns a memory location. In memory it assigns a particular space for that variable value. It is a memory address or memory location.
Example: int a; It assigns a 2byte space for a variable.


Pointers in C | C programming tutorial

See this image normal variable has the value 50 and that address is 1001 and another variable pointer has the address of normal variable 1001.

Benefits of pointers:
1. Pointers increase execution speed.
2. Pointers are more efficient to handle the data tables.
3. They reduce the complexity and the length of program.
4. Pointers enables us to access the variable that are declared outside the function.

Example C program for using pointers:

#include<stdio.h>
void main()
{
int *ptr, c=20;
clrscr();
ptr=&c;
printf("%d",*ptr);
getch();
}

Output:
20

See here pointers are declared using prefix *, so I have declared pointer as *ptr. And c is a normal variable which has value 20. Iam assigning address of c variable to pointer using ptr=&c statement.
And printing the value of variable c through pointer.

I hope you have understand this article 'Pointers in C | C programming tutorial' if you have any questions, ask me in the comment box, I will answer you.



No comments:

Post a Comment