Forum     

Go Back   Digit Technology Discussion Forum > Software > Programming
Register FAQ Calendar Mark Forums Read

Programming The destination for developers - C, C++, Java, Python and the lot


Closed Thread
 
LinkBack Thread Tools Display Modes
Old 07-11-2008, 01:20 PM   #1 (permalink)
Right Off the Assembly Line
 
Manojap's Avatar
 
Join Date: Oct 2004
Location: India,kerala
Posts: 28
Post Pointer Magic


Find sum of 10 nos using array of size 1 and two *pointers


int x[1],i,*xptr,i,*s;

for(i=0;i<10;i++)
{
scanf("%d",&x[i]);
}
xptr=&x;
for(i=0;i<10;xptr++,i++)
{
*s=*s+*xptr;
}
prnitf("%d",*s);
__________________
manojap
Manojap is offline  
Advertisements. Register and be a member of the community to get rid of them.
Advertisement

Old 08-11-2008, 07:51 PM   #2 (permalink)
Right Off the Assembly Line
 
Join Date: Nov 2008
Location: Bangalore
Posts: 6
Default Re: Pointer Magic

I do not understand what is being done in the code! It seems flawed - use of uninitialized pointers, invalid pointer assignments, etc - care to explain?
srinivasa.s is offline  
Old 18-11-2008, 06:10 AM   #3 (permalink)
In The Zone
 
Pragadheesh's Avatar
 
Join Date: Jul 2006
Location: Coimbatore
Posts: 403
Default Re: Pointer Magic

in the first line, 'i' has been declared twice and in the last line, its 'printf' and not 'prnitf'.
other than these errors the program compiles successfully, but doesn't run.

the reason is you used x as 'x[10] instead of x[1]'. i.e u tried to store all the 10 values in consecutive locations of x declaring it as an array of size 1.
declaring x[1] and referencing other indexes like x[2], x[3] etc is the reason for this error.
just type, x[10] in the first line instead of x[1]. it works perfectly. so go for a different logic.
Pragadheesh is offline  
Closed Thread

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Problem with Pointer in Structure veddotcom Programming 5 01-10-2008 09:36 PM
pointer to 2-D array INS-ANI Programming 2 24-03-2008 09:31 PM
Microsoft pointer jumps g_goyal2000 Hardware Q&A 19 02-12-2007 10:34 AM
Mouse pointer behavior patkim Peripherals 3 22-06-2007 02:35 PM
Mouse pointer behaves stupidly @#$%^& kl_ravi Peripherals 1 25-01-2005 10:59 AM

 
Latest Threads
- by gforz
- by soumya
- by Sujeet
- by icebags
- by Charan

Advertisement




All times are GMT +5.5. The time now is 02:58 PM.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2012, vBulletin Solutions, Inc.

Search Engine Optimization by vBSEO 3.3.2