“Known is a drop unknown is an ocean” That everyone knows.
Perhaps there is one more proverb “Little drops of water make a mighty ocean”.
In my blog I am going spare my drop with you, please all of you drop your comments and thoughts on this, hence it become an Ocean.
Today I am going start my first technical notes here.
When I was in college we have a team spent most of the time talking about some different programming styles, I would like to share some small programs which we did in college days.
The first program is in C language, which we did a code that does the addition with single variable using pointers.
The code is as follows
/*********************************************************************/
/* Program for adding the two integers using single pointer variable */
/* Author : Sivasuthan Sivakumaran */
/* Version : 1.0 */
/*********************************************************************/
main()
{
int *x; /* pointer variable declaration */
/* Allocating the memory for pointer variable */
x = (int *) malloc (sizeof(int));
/* get the first value for addition */
printf ("Enter the fist val : ");
scanf("%d",x);
printf( "X val is %d \n", *x);
/* Move the pointer postion to next memory slot */
x++;
/*get the second value for addition */
printf ("Enter the second val : ");
scanf("%d",x);
printf( "X val is %d \n", *x);
/* Move the pointer postion to next memory slot */
x++;
/* Sum the values which is available in previoue two memory slots */
*x = *(x-1) + *(x-2);
printf("value is %d", *x);
return 0;
}
/* End of the program */
Friday, November 20, 2009
Subscribe to:
Post Comments (Atom)

3 comments:
Good start Siva,
really I appreciate your view. my pleasure to share my knowledge.
Seems it's a good start siva. I am sure we would learn a lot of similar stuffs here!
By the wasy, this code should have produced "Segment fault" since memory for second value and sum were not allocated.
Hope this is what you intented...
int *x;
x = (int *) malloc (sizeof(int)*2); /* for 2 nos */
scanf("%d",x); /* first no */
x++; /* to second no */
scanf("%d",x); /* second no */
*x += *(x-1); /* sum with first no */
printf("sum is %d", *x);
Hi Samy,
Thanks for your comments, it is nice to see, your suggestion it helps me to improve my technical staff.
Your comment remains me Henry Ford quotes “Everything can always be done better than it is being done.”
Post a Comment