Ask Experts Questions for FREE Help!
  Advanced
Register  |  Log in  
   Ask    
 Answer  
  Help  

Ask QuestionsprogressAnswer QuestionsprogressBuild ReputationprogressBecome an Expert
 
Free Answers in 3 Easy Steps

Register Now
3 Steps

At Ask Me Help Desk you can ask questions in any topic and have them answered for free by our experts. To ask questions or participate in answering them you must register for a free account. By registering you will be able to:
  • Get free answers from experts in any of our 300+ topics.
  • Accept money for answers that you provide.
  • Communicate privately with other members (PM).
  • See fewer ads.

Home > Computers & Technology > Programming > Compiled Languages > C   »   C program execution sequence

 
Question Tools Search this Question Display Modes
Question
 
 
#1  
Old Jan 3, 2008, 12:40 AM
jinish
New Member
jinish is offline
 
Join Date: Dec 2007
Posts: 1
jinish See this member's comment history on his/her Profile page.
C program execution sequence

Explain C program execution,what are happened during executing a C program?

Reply With Quote
 
     

Answers
 
 
Old Jan 5, 2008, 09:02 AM   #2  
asterisk_man
Full Member
asterisk_man is offline
 
asterisk_man's Avatar
 
Join Date: Nov 2006
Location: East coast of U.S.A.
Posts: 472
asterisk_man See this member's comment history on his/her Profile page.
Please review your class notes and/or textbook for this answer. We do not do your homework for you.
  Reply With Quote
 
     
 
 
Old Jan 6, 2008, 07:21 AM   #3  
sivasayanth
New Member
sivasayanth is offline
 
sivasayanth's Avatar
 
Join Date: Jan 2008
Posts: 1
sivasayanth See this member's comment history on his/her Profile page.
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"
  Reply With Quote
 
     
 
 
Old Feb 25, 2008, 09:52 PM   #4  
slapshot_oi
New Member
slapshot_oi is offline
 
Join Date: Feb 2008
Posts: 26
slapshot_oi See this member's comment history on his/her Profile page.
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 everytime 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:
C Code:
#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.
  Reply With Quote
 
     


Question Tools Search this Question
Search this Question:

Advanced Search
Display Modes

 
Similar Sponsors

Similar Questions
Question Asker Topic Answers Last Post
Wage Execution SnakeBite Credit 0 Nov 30, 2007 02:39 PM
execution of judgment? GGentry Credit 2 Nov 20, 2007 05:47 AM
writ of execution in pa pasam68 Bankruptcy & Debt 0 Oct 30, 2007 06:50 AM
Writ of Execution ixc007 Small Claims 15 Feb 14, 2007 07:45 AM
Execution computer-ops Other Software 2 Mar 12, 2005 07:48 AM




Copyright ©2003 - 2007, Ask Me Help Desk.
All times are GMT -8. The time now is 05:09 PM.

Content Relevant URLs by vBSEO 3.0.0 RC6 © 2006, Crawlability, Inc.