Ask Experts Questions for FREE Help !
    jinish's Avatar
    jinish Posts: 1, Reputation: 1
    New Member

    Jan 3, 2008, 02:40 AM
    C program execution sequence
    Explain C program execution,what are happened during executing a C program?
    asterisk_man's Avatar
    asterisk_man Posts: 476, Reputation: 32
    Full Member

    Jan 5, 2008, 11:02 AM
    Please review your class notes and/or textbook for this answer. We do not do your homework for you.
    sivasayanth's Avatar
    sivasayanth Posts: 1, Reputation: 1
    New Member

    Jan 6, 2008, 09:21 AM
    Quote Originally Posted by jinish
    Explain C program execution,what are happened during executing a C program?
    I can give one hint or link

    I hope this link will help you

    Howstuffworks "How C Programming Works"

    Howstuffworks "How C Programming Works"
    slapshot_oi's Avatar
    slapshot_oi Posts: 1,537, Reputation: 589
    Ultra Member

    Feb 25, 2008, 11:52 PM
    Quote Originally Posted by jinish
    Explain C program execution,what are happened during executing a C program?
    Homework? You have no idea if this is jinish's homework, give him a break asterik_man, it's s simple question, that is what this whole forum is for anyway, questions.

    Memory is organized into four segments:

    Runtime Stack - This is used every time a function is called, main() included. Each record on the stack is called an activation record which stores the function's parameters, the return address of the caller function, and locally defined variables, in that order.
    Heap - A dynamically growing portion of memory, when you use malloc() or define an array, this is where they are stored. Advanced C programs make use of the heap, it's a pain to maintain though.
    Static area - Static and global variables are stored here throughout the life of the program.
    Text area - The assembly code of the program is stored here, this is for the operating system, the programmer can't access this portion of memory.

    Below is an example:
    #include <stdio.h>

    int foo ( int arg ) ;

    int foo ( int arg ) {
    int ans = 10 ;
    arg += ans ;
    return ans ;

    int main ( int argc, char* argv[] ) {
    int num = 5;
    foo ( num ) ;
    return 0 ;

    UNIX calls main() and pushes it as an activation record on to the runtime stack. In main's activation record lies argc and argv, followed by a return address back to UNIX and the variable num. Then main() calls foo() which is also pushed on to the runtime stack as an activation record. When foo() returns it value back to main(), foo() is popped off the runtime stack and the record (activation record) of arguments passed and locally defined variables are lost forever, this is a call by value language at work. If you wish to avoid this, use pointers. Finally, when main() returns to UNIX--the return 0 is the error code--it too is popped off the runtime stack and your program is no longer running.

    This is a bad explanation if you can't visualize what I'm saying. My professor had us commit to memory what it all looks like, and I haven't forgot it.
    sumi_bose's Avatar
    sumi_bose Posts: 4, Reputation: 1
    New Member

    Feb 21, 2011, 06:12 AM
    The compilation and execution process of C can be divided in to multiple steps:
    • Preprocessing - Using a Preprocessor program to convert C source code in expanded source code. "#includes" and "#defines" statements will be processed and replaced actually source codes in this step.
    • Compilation - Using a Compiler program to convert C expanded source to assembly source code.
    • Assembly - Using a Assembler program to convert assembly source code to object code.
    • Linking - Using a Linker program to convert object code to executable code. Multiple units of object codes are linked to together in this step.
    • Loading - Using a Loader program to load the executable code into CPU for execution.

Not your question? Ask your question View similar questions


Question Tools Search this Question
Search this Question:

Advanced Search

Add your answer here.

Check out some similar questions!

Execution of judgment? [ 2 Answers ]

I live in NC and a lawyers office representing a credit card company rec'd a judgment against me a couple of weeks ago for $5000.00 and now they are threatening to get an execution of judgment against me and have the sheriff's office get involved! I'm currently separated (though no legal paperwork...

Writ of Execution [ 15 Answers ]

I have a small claims that went into a default judgement. A friend of mine was sueing me for $400.00... and at the end since I missed the court date I ended up owing him $1674.64. Ok so there was a default judgement placed. I received a letter from the Sheriff regarding the Writ to Execute. So I...

Execution [ 2 Answers ]

I have a redhat 7.3 linux box with cobol 4.1 installed. I upgraded to redhat linux 9.0. When I try to install cobol license manager it gives error rts32 error 114 while executing the command. The compiler works but one cannot execute programs :(

View more questions Search