Yahoo Answers is shutting down on May 4th, 2021 (Eastern Time) and the Yahoo Answers website is now in read-only mode. There will be no changes to other Yahoo properties or services, or your Yahoo account. You can find more information about the Yahoo Answers shutdown and how to download your data on this help page.

Anonymous
Anonymous asked in Computers & InternetProgramming & Design · 1 decade ago

Can anyone explain the Basic Structure of C program by explaining a program?

I want matter indepth.

Update:

I am asking about C program's Structure,

---------------------------------------------------------------------------------------

Documentation Section

---------------------------------------------------------------------------------------

Link Section

---------------------------------------------------------------------------------------

Definition Section

---------------------------------------------------------------------------------------

Global Declaration Section

---------------------------------------------------------------------------------------

main() Function Section

{

Declaration part

Executable part

}

----------------------------------------------------------------------------------------

Subprogram Section

Function1

Function2

-

-

Function n (User-defined functions)

-----------------------------------------------------------------------------

Update 2:

oh my.............. i am asking for a simple program that explains the structure of a c program..............

7 Answers

Relevance
  • 1 decade ago
    Favorite Answer

    John Doe to the contrary, C is a procedural language which evolved with the UNIX operating system in the early 70's. C++ is a superset of C (meaning it includes C but is larger) and has been described by its creator as C with objects and namespaces. So, for a basic structure of a C program:

    #include <stdio.h>

    //That is the basic input/output header file which usually #includes the basic library

    //stdlib.h. Both define functions which are linked to in the libc library. It is important to

    //understand that you need header files and libraries to do just about anything in C or C++

    int Sum(int , int);

    //You declare a function prototype before the main function if you intend to use this function.

    //You can actually declare the whole function up here, but people like to define the functions

    //afterwards. If you don't at LEAST declare it as above, the compiler won't know what to do when

    //it sees it. Notice I did not name the parameters I sent it yet -- I'm just telling the compiler to

    //set aside space for two integer parameters. I end it with a semicolon because unless a line //starts with a # or --usually -- ends with a } you terminate ALL statements with semicolons

    int main(){

    //C only has functions. And UNIX uses the integer returned by main() to determine whether the //program terminated normally. C has void functions which return nothing, but main() always

    //returns an integer.

    int a, b; //declaring the integers I use.

    printf("Enter a number:");

    //The first output statement. Prompting for an entry.

    scanf("%d", &a);

    //input statement. Everything in quotes is called the format string. %d means read

    //a decimal number (from the keyboard). &a means the address of a. Always send

    //scanf a pointer to an address or an address to write to.

    printf("Enter another number:");

    //Another output statement. Just a format string, notice.

    scanf("%d", &b);

    //The second input statement. See above.

    printf("The sum of %d and %d is %d.\n", a, b, Sum(a,b));

    //Final output statement. In the format string you put text and the format of the variables you

    //will print out. Then a comma, and the variables. You can obviously send printf a function and it

    //will call and evaluate it (Sum(a,b)) using that number. the \n is a new line character.

    // It means end the line after you print out the statement. And of course the line ends

    //with a semicolon. This is the actual format for both printf and scanf, but scanf doesn't print

    //anything

    return 0;

    //Tell UNIX that all's well that ends well.

    }

    //C wants the close bracket for main on its own line usually.

    int Sum(int a, int b){

    //Now we are defining it and I have named the parameters for the function.

    //You do not have to give them the same names as in the main() function

    //but if you get too creative people will get confused. Also, since we are

    //not in main() we are in global space.

    return a+b;

    //Simple enough: return the sum of the parameters

    }

    //end program.

    Does that help? Basic structure: Include files, declare or define functions and global variables, main function then define any function declared but not defined.

  • ?
    Lv 4
    4 years ago

    Basic Structure Of C Programming

  • Anonymous
    1 decade ago

    Ashley,

    Are you asking for some one to explain how C programs are in general structured, or are you asking for a *program* that can look at and analyze C programs and tell you the structure? The former is easier (though it is possible to write programs that don't follow the general structure), but the latter is next to impossible.

  • 1 decade ago

    Hmm, that is a very large question to answer.

    C is an object oriented programming language. Objects have 3 things, events, methods, and properties. Events are things the program can't predict (such as the user pressing a button, or resizing the form). Methods are actions (such as minimize the window, or move). Properties are characteristics (color, size).

    I don't think I can give you a whole lecture on here, but what I think you should do is just download Visual C++ and mess with it.

    http://www.microsoft.com/Express/VC/

    Good luck programming

  • 5 years ago

    here is a tutorial about basic structure of a c program.

  • link
    Lv 7
    1 decade ago

    You need to ask a specific question. It would take a whole book to explain C programming.

    Get yourself a copy of Kernighan and Ritchie's C programming book. All will be revealed. It's a slim little book, but it's the best one out there.

  • 1 decade ago

    Well first you need to define whether you are talking about C# or C++ which is used in a wide variety of programs.

Still have questions? Get your answers by asking now.