small program will not compile in C (on linux server)

Posted on 2011-05-09
Last Modified: 2012-05-11
I am brand new to C and pointers and am working through some tutorials and going back over lectures to improve my foundation/survive my course.  This is NOT homework.  I just cannot figure out why I am getting this compile error on this program (which I have copied verbatim from my lecture notes).  

#include <stdio.h>
#include <stdlib.h>

int main ()

int i;
int* iptr = &i;

for (iptr* = 0; *iptr < 10; (*iptr)++)



Open in new window

Question by:dazedandconfused69
    LVL 31

    Accepted Solution

    A quick look and I see one sure typo:
        for (iptr* = 0; *iptr < 10; (*iptr)++)
    reverse the iptr and the * to be *iptr.
    LVL 31

    Expert Comment

    BTW, some people claim that
    should be written as
    since the latter is more efficient (since a temporary copy need not be made).

    I would hope that a good optimizing compiler would see that
    in isolation, would be equivalent to
    and optimize this for you.

    Author Comment

    Argh - now I see the typo - sorry - this was a dumb question.  

    Author Closing Comment

    Thanks for answering this very dumb question.
    LVL 31

    Expert Comment

    Not dumb question - actually mistakes like this are common. I make them a lot. Sometimes, I can't see what is wrong, and I just write the section over again from scratch and it works. Then I look at my commented out version and have a good laugh. A second set of eyes is often useful.
    LVL 53

    Expert Comment

    >> I would hope that a good optimizing compiler would see that

    For types like int, yes. However, for user-defined types that is generally not the case.
    The reason to always prefer pre-increment over post-increment (even though you're sure it won't matter for the specific type you're working with), is to teach yourself a good habit.

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Highfive + Dolby Voice = No More Audio Complaints!

    Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

    Suggested Solutions

    Title # Comments Views Activity
    abstract class with all non abstract mentods 6 58
    copyEndy  challenge 15 38
    wordlen challenge 3 27
    groovy example issue 10 32
    This is a short and sweet, but (hopefully) to the point article. There seems to be some fundamental misunderstanding about the function prototype for the "main" function in C and C++, more specifically what type this function should return. I see so…
    Whether you've completed a degree in computer sciences or you're a self-taught programmer, writing your first lines of code in the real world is always a challenge. Here are some of the most common pitfalls for new programmers.
    Video by: Grant
    The goal of this video is to provide viewers with basic examples to understand and use for-loops in the C programming language.
    The goal of this video is to provide viewers with basic examples to understand and use switch statements in the C programming language.

    761 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    12 Experts available now in Live!

    Get 1:1 Help Now