Skip to content
Utopper skill
  • ProgrammingExpand
    • Programming Examples
  • Interview QuestionsExpand
    • DevOps Interview Questions
    • Android Interview Questions
  • How to
  • Tools
  • Top 10
  • Book Summaries
Utopper skill

C Program Structure

C Programming Course

Page Index


C Overview

C Environmental Setup

C Program Structure

C Basic Syntax

C Programming Blocks

C Printf and Scanf

C Data Type

C Variables

C Constant

C Keywords

C Operators

C Comments

C Identifier

C Literals

C Tokens

C Format Specifier

ASCII Value in C

C If Statement

C If Else Statement

C Nested If Statement

C Switch Case

C Nested Switch

C If Else vs Switch

C Loops

C For Loop

C While Loop

C Do While Loop

Nested Loop in C

Infinite Loop in C

C Break

C Continue

C goto

Typecasting in C

C Function Basic

Call By Value

Call By Reference

Recursion in C

Storage Classes

C Array Basics

1-D Array in C

2-D Array in C

Passing Array to Function

Return Array from a Function

Multi-Dimensional Array in C

Pointer to an Array in C

C Pointer

Pointer Arithmetic

Array of Pointers

C Pointer to Pointer

Passing Pointer to Function in C

Return Pointer From Function in C

Dangling Pointer in C

sizeof() Operators in C

Const Pointers in C

Void Pointer in C

C Deference Pointer

Null Pointer in C

C Function Pointer

C String Basics

C gets() and puts()

C String Function

C Structure Basics

typedef in C

C Bit Fields

C Array of Structure

C Nested Structure

Structure Padding in C

C Union

C File Handling Basics

C fprintf() fscanf()

C fputc() fgetc()

C fputs() fgets()

C fseek()

C rewind()

C ftell()

C Preprocessor Basics

C Macros

C #include

C #define

C #undef

C #ifdef()

C #ifndef()

A basic C program consists of the following parts:

1. Preprocessor Directives / Header Files : The preprocessor directives are instructions for the C preprocessor, which is a program that processes the source code before it is compiled. The most common preprocessor directive is #include, which is used to include header files that provide function and variable declarations. For example, the following line of code includes the standard input/output header file. They are included at the beginning of the program using the #include directive.

#include <stdio.h>

2. Main Function: The main function is the entry point of the program, and it is where the program execution begins. The main function has a return type of int and takes no arguments by default. The main function is defined as follows:

int main() {
    // statements
    return 0;
}

The return 0 statement at the end of the main function indicates that the program has executed successfully.

3. Declarations: The declarations section contains variable and function declarations. It is located before the main function and is used to tell the compiler what types of variables and functions the program uses. For example, the following code declares a variable named x

int x;

4. Statements: The statements section contains the actual code that performs the tasks of the program. The statements are executed in sequence, one after the other. For example, the following code uses the printf function to display a message to the user

printf("Hello, World!");

The printf function takes a string argument, which is enclosed in double quotes.

Putting it all together, a basic C program that displays “Hello, World!” on the screen would look like this:

#include <stdio.h>
int main() {
    printf("Hello, World!");
    return 0;
}

This program includes the stdio.h header file, which provides the printf function. The main function uses the printffunction to display the message “Hello, World!” to the user. The return 0 statement at the end of the main function indicates that the program has executed successfully.

Compile and Execute the Above C Program Step by Step :

To compile and execute the basic “Hello, World!” program in C, follow these steps:

  1. Open a text editor: Open a text editor of your choice, such as Notepad or Sublime Text.
  2. Write the program: Write the following code in the text editor:
#include <stdio.h>
int main() {
    printf("Hello, World!");
    return 0;
}
  1. Save the program: Save the program with a .c extension. For example, you can save it as hello.c.
  2. Open a terminal: Open a terminal or command prompt on your computer.
  3. Navigate to the directory: Navigate to the directory where the program is saved using the cd command.
  4. Compile the program: Compile the program using the following command:
gcc -o hello hello.c

This will compile the program and generate an executable file named hello.

7. Execute the program: Execute the program by running the following command:

./hello

This will run the program and output “Hello, World!” to the terminal.


Our Latest Posts

  • Git Interview Questions
    35 + GIT Interview Questions
  • Book Summary of Why We Sleep By Matthew Walker
    Book Summary of Why We Sleep By Matthew Walker
  • C Program to Print Your Own Name
    C Program to Print Your Own Name with Example
  • Facebook
  • Instagram
  • YouTube
  • Telegram
  • LinkedIn
  • Twitter

Mail : [email protected]

Privacy Policy | DISCLAIMER | Contact Us

Learn Development

learn HTML

learn CSS

learn JavaScript

Examples

C Examples

C++ Examples

Java Examples

Study Material

Interview Questions

How to

Hosting

SEO

Blogging

© 2023 Utopper.com

All Rights Reserved with Copyright & Registered TradeMarks
OWNED BY : GROWTH EDUCATION SOLUTIONS PRIVATE LIMITED

Scroll to top
  • Programming
    • Programming Examples
  • Interview Questions
    • DevOps Interview Questions
    • Android Interview Questions
  • How to
  • Tools
  • Top 10
  • Book Summaries
Search