C Basic Commands

Last Updated :

C is a high-level programming language that was developed in the 1970s and is still widely used today. It is used to develop a wide range of applications, including system software, games, and desktop and mobile applications. Here are some of the most commonly used C commands:

  1. printf: This function is used to display output on the screen.
    Example –

    #include <stdio.h>
    
    int main() {
       printf("Hello, World!");
       return 0;
    }
    
    
  2. scanf: This function is used to read input from the keyboard.
    Example – 

    #include <stdio.h>
    
    int main() {
       int a;
       printf("Enter a value: ");
       scanf("%d", &a);
       printf("You entered: %d", a);
       return 0;
    }
    
    
  3. main: This is the starting point of a C program. It returns an integer value to indicate the status of the program’s execution.
    Example –

    #include <stdio.h>
    
    int main() {
       printf("This is the starting point of the program.");
       return 0;
    }
    
    
  4. if: This statement is used to execute a block of code conditionally.
    Example –

    #include <stdio.h>
    
    int main() {
       int a = 5;
       if (a > 0) {
          printf("a is positive.");
       }
       return 0;
    }
    
    
  5. for: This loop is used to repeat a block of code a specified number of times.
    Example –

    #include <stdio.h>
    
    int main() {
       int i;
       for (i = 1; i <= 10; i++) {
          printf("%d ", i);
       }
       return 0;
    }
    
    
  6. while: This loop is used to repeat a block of code as long as a condition is true.
    Example –

    #include <stdio.h>
    
    int main() {
       int i = 1;
       while (i <= 10) {
          printf("%d ", i);
          i++;
       }
       return 0;
    }
    
    
  7. do-while: This loop is similar to a while loop, but the block of code is executed at least once.
    Example –

    #include <stdio.h>
    
    int main() {
       int i = 1;
       do {
          printf("%d ", i);
          i++;
       } while (i <= 10);
       return 0;
    }
    
    
  8. break: This statement is used to exit a loop early.
    Example –

    #include <stdio.h>
    
    int main() {
       int i;
       for (i = 1; i <= 10; i++) {
          if (i == 5) {
             break;
          }
          printf("%d ", i);
       }
       return 0;
    }
    
    
  9. continue: This statement is used to skip the current iteration of a loop and move on to the next one.
    Example –

    #include <stdio.h>
    
    int main() {
       int i;
       for (i = 1; i <= 10; i++) {
          if (i % 2 == 0) {
             continue;
          }
          printf("%d ", i);
       }
       return 0;
    }
    
    
  10. switch: This statement is used to choose between multiple blocks of code to execute based on a value.
    Example –

    #include <stdio.h>
    
    int main() {
       int a = 2;
       switch (a) {
          case 1:
             printf("a is 1.");
             break;
          case 2:
             printf("a is 2.");
             break;
          default:
             printf("a is neither 1 nor 2.");
       }
       return 0;
    }
    
    

These are just a few of the many commands available in the C programming language. If you are new to C, it’s a good idea to start by learning these basics before diving into more advanced topics.

 

Please write comments below if you find anything incorrect, or you want to share more information about the topic discussed above. A gentle request to share this topic on your social media profile.

Comment
Next Article
Mithlesh Upadhyay Published 14 Feb, 2023 · 3 min read

Mithlesh Upadhyay is a Computer Science and AI expert from Madhya Pradesh with strong academic background (BE in CSE and M.Tech in AI) and over six years of experience in technical content development. He has contributed tech articles, led teams, and worked in Full Stack Development and Data Science. He founded the w3colleges.org portal for learning resources.

Article Tags :

Similar Reads

  • What should we use void main() or int main() ?

    There is question that what should we use void main() or int main() ? void main() { /* ... */ } Or, int main() { /* ... */…

    2 min read
  • C Comments

    Prerequisite – C Language Introduction C comments explain code and improve readability. These do not affect program execution. You can use comments in C to clarify code and describe…

    1 min read
  • C Programming Language Standard

    Prerequisite – C Language Introduction The C programming language has various versions: C89/C90, C99, C11, and C18. C89/C90: Released in 1989/1990. It introduced key language features. C99: This…

    2 min read
  • Features of C Programming Language

    Prerequisite – C Language Introduction C is a simple language made in 1972 by Dennis Ritchie. It’s for system programming. C has low-level memory access, basic keywords, good…

    1 min read
  • C Language Introduction

    C is a programming language developed by Dennis Ritchie in 1972. It has a significant historical impact. It was originally created at Bell Laboratories of AT&T Labs for…

    4 min read
  • Code editors

    Code editors are where programmers spend most of their time. There are two main types of code editors: IDEs and Lightweight editors. IDEs (Integrated Development Environments) IDEs (Integrated…

    1 min read