[ Home  |  FAQ-Related Q&As  |  General Q&As  |  Answered Questions ]

    Search the Q&A Archives

1. What happend in general whan a computer program is...

<< Back to general questions

Question by Siraj ul Hassan
Submitted on 7/12/2003
Related FAQ: N/A
Rating: Rate this question: Vote
1.  What happend in general whan a computer program is executed?
2.  What are the characteristics of C language on other languages?
3.  What is the basic structure of c program?

Answer by Chris Hale
Submitted on 7/14/2003
Rating:  Rate this answer: Vote
   Answer 1: This can vary depending on the type of central processor unit and the architecture of the system. But here goes...

When the CPU is reset, a special register known as the "Program Counter" or 'PC' (a register is a piece of memory reserved for holding the address of the next program instruction to be executed)is set to the starting point of the whole system. This is usually referred to as the Reset (Interrupt) Vector. The CPU loads the value stored in the Reset Vector. This value will be the address of where the main program begins. A bit like a "Goto" statement in basic. This new address is loaded into the PC and the CPU 'jumps' to this location. An instruction can be 1,2 or even 3 bytes in length. The first 1 or 2 bytes are the instruction code. The next 2 or 3 byte would be the data or the address accompanying the command. Once the command is executed the PC increments itself to the next memory location and then the process starts over. There is another architecture called a "Harvard Architecture" where while one instruction is being executed the next instruction is being 'fetched' from memory. This type architecture is used in DSP's (Digital Signal Processors) because they are much faster.

Answer 2: The C language is very much like Basic or other high level programs in some respects. It's greatest advantages are... That because it's compiled and not interpreted it runs faster: It doesn't have to stop and interpret each instruction before it executes it. The program is already compiled into a language the computer can understand and so runs faster. It's compartmentalised, which means that specific tasks can be written as something called a 'function' which can be 'called' as many times a necessary by the main program and can be REUSED. This makes the tracking down and managing of software bugs easier because the functions are isolated from each other. So changes to one function generally cannot affect another It's a lot easier to read than assembler language for instance.

You can also have the functions you have written stored in 'Libraries' with other standard functions that come with the software package and are regulated by a standard known as 'ANSI'.

An example of a 'C' program....


int main(void)
  printf("Hello World\n");

  return FALSE;

Note use of the three functions setcursortype, clearscreen, printf.

I think you'll agree that this is a lot easier to read than say ASSEMBLER language.

Answer 3: The basic structure consists of the 'main' function. All functions have a name, a list of arguments and the code body is enclosed between '{' '}'. If your own functions are part of your main source file (the files that you write your code to) and are not saved seperately as library files you have to put what is called a 'function prototype' at the start of the file BEFORE your code. This is so the linker knows how much memory on the stack to reserve when creating the space for your function EG...

/* Function Prototype (returns an integer)*/
int myfunction(int a, int b);

/* Main Program */
int main(void)
  for (x=0; x < 10; x++) {
  printf("Value = %i\n",myfunction(x,2));

/* Function declared by author. */
/* Multiples a by b and returns the result.*/
int myfunction(int a, int b)
  int val = 0; /* Local variable only */
               /* visible inside this */
               /* function. */

  val = a * b; /* Multiple 'a' by 'b'. */

  return val; /* Return the result. */

Hope that answers your questions....



Answer by libby
Submitted on 10/31/2004
Rating: Not yet rated Rate this answer: Vote
fred said go to bed


Your answer will be published for anyone to see and rate.  Your answer will not be displayed immediately.  If you'd like to get expert points and benefit from positive ratings, please create a new account or login into an existing account below.

Your name or nickname:
If you'd like to create a new account or access your existing account, put in your password here:
Your answer:

FAQS.ORG reserves the right to edit your answer as to improve its clarity.  By submitting your answer you authorize FAQS.ORG to publish your answer on the WWW without any restrictions. You agree to hold harmless and indemnify FAQS.ORG against any claims, costs, or damages resulting from publishing your answer.


FAQS.ORG makes no guarantees as to the accuracy of the posts. Each post is the personal opinion of the poster. These posts are not intended to substitute for medical, tax, legal, investment, accounting, or other professional advice. FAQS.ORG does not endorse any opinion or any product or service mentioned mentioned in these posts.


<< Back to general questions

[ Home  |  FAQ-Related Q&As  |  General Q&As  |  Answered Questions ]

© 2008 FAQS.ORG. All rights reserved.