First C Program

We will write our first C program.
Here, #include is a preprocessor directive.
<stdio.h> is the C standard Input Output library. It is used to getting input from users via keyboard, and display output on the monitor.

In the C program, there can be multiple functions but only one main() function. It is the entry point of any program in C.

int before the main() function indicates that the return value must be an integer value. At the end of the main() function, we have returned 0 which indicates that success. Any non-zero value indicates failure.

printf() is used to display output on the screen, but for that, we must include <stdio.h> header.

printf(“<format string>”,<list of variables>);

here,
<format string> can be

%f for printing  the real values
%d for printing the integer value
%c for printing the character value

<list of variables> must be the variable list corresponding to that format specifier.

int rollno = 20;
printf(“rollno = %d”, rollno);
#include<stdio.h>

int main() {
    printf("Hello, world!\n");
    printf("Welcome to mycomputerknowledge.com!\n");
    return 0;
}

Output

$ gcc hello.c
$ ./a.out
Hello, world!
Welcome to mycomputerknowledge.com!

also see

C Programming language
Go Programming language
Linked List Array
Simplification Queue
DBMS Reasoning
Aptitude HTML
Previous articleReverse a string using stack
Next articlePrint Inversions in an array in C

LEAVE A REPLY

Please enter your comment!
Please enter your name here