Structure of C Program

1. Include Statements:

These are like saying, "Hey, computer, I'm going to use some special tools, so get ready." It's the beginning of your program.

                                                        #include <stdio.h>

In this example, we're telling the computer to include (or use) the tools from the stdio.h library, which helps with input and output.


2. Main Function:

This is like the starting point of your program. It's where the computer begins reading and doing what you tell it.

                                                int main() 

                                                {

                                                        // Your code goes here

                                                        return 0; // This means everything went well

                                                }

int main() is like saying, "Hey computer, here comes the main part of my program!" 

The {} curly braces hold the instructions for the computer to follow. The return 0; is like saying, "I'm done, and everything went okay."


3. Comments:

Comments are like sticky notes to yourself (or others) to explain what your code is doing. The computer ignores them.

                                                // This is a comment. It helps explain things.


4. Declarations:

Here, you tell the computer about the boxes (variables) you want to use. It's like saying, "I'm going to store some information, get ready."

                                                int age; // This is a box for storing whole numbers (integer)

                                                float height; // This is a box for storing decimal numbers (float)

You're declaring the types of data your program will work with.


5. Input/Output:

You might want your program to talk to the user or listen to what they say. printf() is like talking, and                                                    scanf() is like listening.

                                                printf("Enter your age: ");

                                                scanf("%d", &age);

Here, you're telling the computer to say something and then listen for a whole number (integer) that the user types. &age is like telling the computer where to store that number.


6. Actions:

This is where the real work happens. You tell the computer what to do with the information it has.

                                                height = 5.8; // Assigning a value to the height box

Here, you're telling the computer that the height is now 5.8.


7. Output:

You might want the computer to show you something. printf() is again your friend.

This line tells the computer to say the age and height it knows.


8. The End:

The return 0; at the end is like saying, "I'm done, and everything went okay." It's a way to wrap up your program.




Post a Comment

0 Comments