Address + Number= Address Address - Number= Address Address - Address=Number Address + Address=Illegal
Translate
Labels
- 2-D ARRAY TO 1-D ARRAY
- ABOUT C
- ACHROMATIC STRING
- ADAM NUMBER
- ALPHABET
- ARRAY PROGRAMS
- ASCII
- BACKGROUND FOR FACEBOOK
- BASIC UNIX COMMANDS
- BINARY TO DECIMAL
- BOMB GAME
- C GAMES
- C++ APTITUDES
- CALCULATION ON COMMAND PROMPT
- CALENDER IN C
- CD BURNING
- CHAT WITH YOUR FRIENDS USING MS-DOS
- CLIENT SERVER IMPLEMENTATION
- COMMAND PROMPT
- COMPUTER NETWORKS
- CONDITIONAL PROGRAMS
- CONDITIONAL STATEMENTS
- CONSTANTS
- CONTROL OVER A TO Z
- CONVERSION OF INTEGER INTO WORDS
- DATA STRUCTURES APTITUDE
- DATA TYPES
- DATE AND TIME
- EBOOKS
- ENABLING AND DISABLING THE KEYBOARD
- EXECUTION TIME OF A PROGRAM
- FACT CORNER
- FIBONACCI SERIES
- FILE EXTENSIONS
- FUNCTIONS
- GCD
- GENERATE PERFECT NUMBER
- GET BACK HIDDEN DRIVE
- GETTING THE DISK STATUS
- GMAIL
- HACKS
- HIDE DRIVE IN MY COMPUTER
- IDENTIFIERS
- INTERNET EXPLORER SHORTCUTKEYS
- JPEG TO BMP
- KNAPSACK PROBLEM
- LOOP PROGRAMS
- LOOP STATEMENT
- MACRO CALL
- MENU DRIVEN ENVIRONMENT IN C
- MESSAGE QUEUE FOR IMPLEMENTING MERGE SORT
- MULTIPLICATION TABLE USING C
- n-QUEEN'S PROBLEM USING BACKTRACKING
- NATURAL NUMBER
- NUMBER
- ONE DIMENSIONAL ARRAY
- PALINDROME
- PASCAL'S TRIANGLE
- PATTERNS
- PENDRIVE
- PERFECT NUMBER
- PERFECT SQUARE
- POINTER
- POINTER VARIABLE
- PRIME NUMBER
- PROGRAM FOR SCROLLING THE WINDOW UP
- PROGRAM TO CATCH ctrl+c
- PROGRAMMING LANGUAGES
- PROGRAMS
- PUZZLE
- QUEER NUMBERS
- QWERTY
- RDBMS CONCEPTS
- RE-CALIBRATE COMMAND
- READING THE DISK'S DATA
- RESETTING THE FDC
- RUNTIME ERRORS
- SCROLLING THE WINDOW DOWN
- SETTING CURSOR POSITION
- SETTING CURSOR SIZE
- SHELL PROGRAMS
- SHORTCUT KEYS
- SHUTDOWN TIMER
- SIMPSON'S RULE
- SORT PROGRAMS
- SOURCE FILES
- SQL
- STACK
- STARS
- STORAGE CLASSES
- STORE A FLOAT VALUE IN THE MEMORY
- STRING
- STRING LITERAL
- SWAPPING WITHOUT TEMP VARIABLE
- TECHNICAL APTITUDE
- TERMINATION
- TOWER OF HANOI
- TRANSPOSE MATRIX
- TRAPEZOIDAL RULE
- TRICKS
- TSR AND TSO
- TURN ON LOCKS
- UNIX CONCEPTS
- VERIFYING THE DISK SECTOR
- WINDOWS
- X TO THE POWER Y
Showing posts with label POINTER. Show all posts
Showing posts with label POINTER. Show all posts
Sunday, 16 June 2013
Saturday, 2 March 2013
ONE DIMENSIONAL ARRAYS USING POINTERS
#include<stdio.h>
#include<conio.h>
void main()
{
int a[10],n,i;
clrscr();
printf("Enter no of elements\n");
scanf("%d",&n);
printf("Enter %d elements \n",n);
for(i=0;i<n;i++)
scanf("%d",a+i);
printf("The list if elements \n");
for(i=0;i<n;i++)
printf("%d \n",*(a+i));
getch();
}
In the above program, a is declared to be an array of int type of size 10.n and i are declared to be variables of int type.The variable n is to accept the number of elements to be accepted into array a, the value of which should lie within 1 and 10 and the variable i is to select each location of the array.We know that the array name a gives the address of the first location of the array and the expression a+i gives the address of the first location of the array and the expression a+i gives the address of i th location of the array.the following segment enables us to accept n values into the array.
for(i=0;i<n;i++)
scanf("%d",a+i)
The second argument a+i is equivalent to &a[i].*(a+0) gives the value at the first location of the array and in general,*(a+i) gives the value at i th location of array a.The following segment displays the n values stored in the array.
for(i=0;i<n;i++)
printf("%d \n",*(a+i));
the second argument *(a+i) is equivalent to a[i].
#include<conio.h>
void main()
{
int a[10],n,i;
clrscr();
printf("Enter no of elements\n");
scanf("%d",&n);
printf("Enter %d elements \n",n);
for(i=0;i<n;i++)
scanf("%d",a+i);
printf("The list if elements \n");
for(i=0;i<n;i++)
printf("%d \n",*(a+i));
getch();
}
In the above program, a is declared to be an array of int type of size 10.n and i are declared to be variables of int type.The variable n is to accept the number of elements to be accepted into array a, the value of which should lie within 1 and 10 and the variable i is to select each location of the array.We know that the array name a gives the address of the first location of the array and the expression a+i gives the address of the first location of the array and the expression a+i gives the address of i th location of the array.the following segment enables us to accept n values into the array.
for(i=0;i<n;i++)
scanf("%d",a+i)
The second argument a+i is equivalent to &a[i].*(a+0) gives the value at the first location of the array and in general,*(a+i) gives the value at i th location of array a.The following segment displays the n values stored in the array.
for(i=0;i<n;i++)
printf("%d \n",*(a+i));
the second argument *(a+i) is equivalent to a[i].
Friday, 1 March 2013
POINTER OPERATORS & AND *
#include<stdio.h>
#include<conio.h>
void main()
{
int x=10,*xp;
float y=3.4,*yp;
char z='a',*zp;
clrscr();
printf("x=%d\n",x);
printf("y=%f\n",y);
printf("z=%c\n,z");
xp=&x;
printf("\n Address of x=%u\n",xp);
printf("Value of x=%d\n",*xp);
yp=&y;
printf("\n Address of y=%u\n",yp);
printf("Value of y=%f\n",*yp);
zp=&z;
printf("\n Address of z=%u\n",zp);
printf("Value of x=%c\n",*zp);
getch();
}
#include<conio.h>
void main()
{
int x=10,*xp;
float y=3.4,*yp;
char z='a',*zp;
clrscr();
printf("x=%d\n",x);
printf("y=%f\n",y);
printf("z=%c\n,z");
xp=&x;
printf("\n Address of x=%u\n",xp);
printf("Value of x=%d\n",*xp);
yp=&y;
printf("\n Address of y=%u\n",yp);
printf("Value of y=%f\n",*yp);
zp=&z;
printf("\n Address of z=%u\n",zp);
printf("Value of x=%c\n",*zp);
getch();
}
- In the above program concept of pointer operators illustrated,x,y and z are declared to be variables of int, float and char type, respectively. xp ,yp and zp are declared to be pointer variables of type int, float and char type, respectively.
- The initial values of x, y, and z are displayed. The pointer variable xp is assigned the address of x using the statement xp=&x;the address of x and its value are displayed through the pointer variable.The same thing is repeated for char and float.
Sunday, 30 December 2012
POINTER VARIABLES
The variables in C are classified into ordinary variables and pointer variables.An ordinary variable can take values of its associated type.
eg:
int x;
Here, x is an ordinary variable of type integer and assumes a whole number as its value.
x=10;
A pointer variable is declared as follows:
int *y;
The above declaration is a pointer variable declaration.Here y is a pointer variable whose type is an integer pointer (int*) .
A pointer variable assumes only the address as its value.Each variable takes some locations in the main memory is addressable.
In the above examples,x is an ordinary variables and y is a pointer variable. x is an ordinary integer and y is a pointer to an integer.Hence, we can store the address of x in y.
y=&x;
there are only two operators associated with pointers- an address of (&) operator and an indirection(*) operator.Both operators are unary operators.
since x is an integer it occupies two byte in the memory.
Every byte is addressable in main memory. To obtain the address of the variable we have to use the "address of" operator(&).So in the statement y=&x; the address of x is stored into the pointer variable y.Since y is a pointer variable it can assume only an address of a variable .We can say that y points to x.
Assume the value of x is 10.To retrieve the value of x through pointer variable y( since y already points to x), we can use the "indirection" operator(*)That is *y will give the value contained in the location pointed by y.If the value of x is 10 and the pointer variable y is pointing to x then the value of the expression *y is 10.
In the above example,
eg:
int x;
Here, x is an ordinary variable of type integer and assumes a whole number as its value.
x=10;
A pointer variable is declared as follows:
int *y;
The above declaration is a pointer variable declaration.Here y is a pointer variable whose type is an integer pointer (int*) .
A pointer variable assumes only the address as its value.Each variable takes some locations in the main memory is addressable.
In the above examples,x is an ordinary variables and y is a pointer variable. x is an ordinary integer and y is a pointer to an integer.Hence, we can store the address of x in y.
y=&x;
there are only two operators associated with pointers- an address of (&) operator and an indirection(*) operator.Both operators are unary operators.
since x is an integer it occupies two byte in the memory.
Every byte is addressable in main memory. To obtain the address of the variable we have to use the "address of" operator(&).So in the statement y=&x; the address of x is stored into the pointer variable y.Since y is a pointer variable it can assume only an address of a variable .We can say that y points to x.
Assume the value of x is 10.To retrieve the value of x through pointer variable y( since y already points to x), we can use the "indirection" operator(*)That is *y will give the value contained in the location pointed by y.If the value of x is 10 and the pointer variable y is pointing to x then the value of the expression *y is 10.
In the above example,
- y represents the address of the variable x (&x)
- *y represents the value of the variable x (x)
Subscribe to:
Posts (Atom)