C
  • Introduction
    • Fundamentals of a Program
    • Overview of C
    • Features of C
  • Installing Required Software
    • Setting Up VSCode for Windows
    • Setting Up VSCode for macOS
    • Setting Up VSCode for Ubuntu
  • Starting to write code
    • Compiling and Running Your Code
    • Creating Our First C Program
    • Errors and Warnings
    • Program: Writing a C Program to Display Your Name
    • Structure of a C Program
  • Basic Concepts
    • Comments in C
    • Preprocessor in C
    • The #include Statement
    • Displaying Output
    • Reading Input from the Terminal
    • Enums and Chars
    • Data Types and Variables
    • Format Specifiers
    • Command Line Arguments
    • Program: Calculating the Area of a Triangle
  • Operators
    • Converting Minutes to Years and Days
    • Basic Operators
    • Bitwise Operators
    • Program: Byte Sizes of Basic Data Types
    • cast and sizeof Operators
    • Operator Precedence
  • Control Flow
    • If-Else Statements
    • Program: Weekly Pay Calculation
    • Switch Statement
    • For Loop
    • While and Do-While Loops
    • Nested Loops and Loop Control
    • Program: Guess the Number
  • Arrays
    • Introduction to Arrays
    • Program: Prime Number Generator
    • Multidimensional Arrays
    • Program: simple Weather Program
    • Variable Length Arrays (VLAs)
  • Functions
    • Overview of Functions
    • Defining Functions
    • Arguments and Parameters
    • Returning Data from Functions
    • Variable Scoping
    • Program: Tic Tac Toe Game
    • Recursion
  • Strings
    • Defining a String
    • Constant Strings in C
    • Common String Functions
    • Program: Bubble Sort
    • Searching, Tokenizing, and Analyzing Strings
    • Converting Strings
  • Debugging
    • What is Debugging
    • Understanding the Call Stack
    • Common C Mistakes
    • Understanding Compiler Errors
  • Pointer
    • Defining Pointers
    • Accessing Pointers
    • Program: Pointer Demonstration
    • Pointers and Const
    • Void Pointers
    • String Pointers
    • Array Pointers
    • Utilizing Pointers with Functions
    • Pointer Arithmetic
  • Dynamic Memory Allocation
    • malloc, calloc, and realloc
    • Program: User Input String
    • Memory Deallocation
  • Structure
    • Structures and Arrays
    • Nested Structures
    • Structures and Pointers
    • Structures and Functions
    • Program: Structure pointers and Functions
  • File Input and Output
    • Accessing Files
    • Reading from a File
    • Program: Finding the Total Number of Lines in a Text File
    • Writing to a Text File
    • Finding Your Position in a File
    • Program: Converting Characters in a File to Uppercase
    • Program: Printing the Contents of a File in Reverse Order
  • The Standard C Library
    • Various Functions in C
    • Math Functions in C
    • Utility Functions in C
Powered by GitBook
On this page
  • Understanding the Basics
  • The Structure of a C Program
  • Writing Your First Program
  • Getting Started
  • Compiling and Running Your Code

Was this helpful?

  1. Starting to write code

Creating Our First C Program

Welcome to the world of C programming! In this section, we'll guide you through creating your very first C program. Let's start with the classic "Hello, World!" example.

Understanding the Basics

The Structure of a C Program

Every C program follows a basic structure. Here's a simple template:

#include <stdio.h>

int main() {
    // Your code goes here
    return 0;
}
  • #include <stdio.h>:

    • This line includes the standard input/output library, allowing you to use functions like printf().

  • int main() { ... }:

    • The main() function is the starting point of every C program.

  • return 0;:

    • The return statement ends the main() function. The 0 indicates successful execution.

Writing Your First Program

Now, let's write a simple "Hello, World!" program:

#include <stdio.h>

int main() {
    printf("Hello, World!\n");
    return 0;
}
  • printf("Hello, World!\n");:

    • The printf() function is used to print output to the console. Here, it prints the "Hello, World!" message, and represents a newline character.

Getting Started

  1. Open a Text Editor:

    • Use a text editor of your choice (e.g., Notepad, Visual Studio Code, Sublime Text) to write your C code.

  2. Create a New File:

    • Create a new file with a .c extension (e.g., hello.c) to save your C code.

  3. Write Your Code:

    • Copy and paste the "Hello, World!" code into your file.

  4. Save the File:

    • Save your file.

Compiling and Running Your Code

Once your code is ready, you'll typically compile and run it to see the output. However, let's focus on creating the code in this section.

Congratulations! You've successfully created your first C program. In the next sections, we'll explore more concepts to expand your C programming knowledge.

PreviousCompiling and Running Your CodeNextErrors and Warnings

Was this helpful?