C Programming language

C Standard Library Function

Day 1: Introduction and brief history of C Programming language

Day 1: Advantages and Disadvantages of C, C Keywords, Data type modifiers in C

Day 1: Data types in C Programming language

Day 1: Secondary data types, Primitive and Non-primitive data types

Day 1: C Variables, C Constant, Format Specifiers in C

Day 2: Write first C program

Day 2: Flow of C program with example, main(), printf(), scanf()

Day 2: Operaters in C Programming language, Arithmetic operators

Day 2: Relational operators and Logical Operators in C Programming language

Day 2: Assignment, Increments and Decrement Operators in C Programming language

Day 3: Conditional statement: if else statement in C Programming language

Day 3: Conditional statement: switch statement in C Programming language

Day 3: Jump statements: return statement in C Programming language

Day 3: Jump statements: go to statement in C Programming language

Day 3: Jump statements: break statement in C Programming language

Day 3: Jump statements: continue statement in C Programming language

Day 4: Loops OR Iteration statement in C Programming language: for Loop

Day 4: Loops OR Iteration statement in C Programming language: while Loop

Day 4: Loops OR Iteration statement in C Programming language: do while Loop

Day 5: Array in C Programming language

Day 5: Access elements of Array in C Programming language

Day 5: One dimensional Array representation in memory using C Programming language

Day 5: Two dimensional Array representation in memory using C Programming language

Day 5: Multidimensional Array in C Programming language

Day 6: Function in C Programming language

Day 6: Definition, Declaration and Calling a Function in C Programming language

Day 6: Passing array to a function in C Programming language

Day 6: Calling Function in C Programming language : Call by value

Day 6: Calling Function in C Programming language : Call by reference

Day 6: Recursive Function in C Programming language

Day 6: Adding function to the library in C Programming language

Day 7: Pointer in C Programming language, How to use Pointer, Pointer declaration

Day 7: NULL Pointers in C Programming language

Day 7: Array of Pointers in C Programming language

Day 7: Pointer arithmetic in C Programming language

Day 7: Pointer to Pointer in C Programming language

Day 7: Pointer to Function in C Programming language: Passing pointers to functions

Day 7: Pointer to Function in C Programming language: Return pointer from functions

Day 8: Strings in C Programming language, Declaring String in C Programming language

Day 8: String functions in C Programming language

Introduction of Structure

Accessing the members of Structure

Structure With typedef Keyword and Use of sizeof function

Example of Structure

Dynamic memory allocation in C: Introduction

adplus-dvertising
Day 2 Flow of C program with example, main(), printf(), scanf()
Previous Home Next
#include <stdio.h>
main()
{
	printf("");
}
Preprocessor directive
#include

The ‘#include’ in the first line of the program is called a preprocessor directive. A preprocessor is a program that processes the C program before the compiler. All the lines in the C program beginning with a hash (#) sign are processed by the preprocessor.

"Standard Input/Output Header"

<stdio.h>

stdio.h, stands for "Standard Input/Output Header", ‘stdio.h’ refers to a file supplied along with the C compiler. It contains ordinary C statements. These statements give information about many other functions that perform input-output roles. Library functions are declared in header files. stdio.h provide the information to printf() that what should it do.

main() Function
main()
{
	statement 1;
	statement 2;
}

The next statement is the main() function. As you already know, this is the place where the execution of the C program begins. Without this function, your C program cannot execute.

  • main() is a function which is entry point of any program.
  • main() is collective name which is given to a set of statements.
  • This name has to be main(). It can not be change.
  • Statements within a main() should be enclosed within a pair of { }.

Difference between main() and other functions

  • parameters to main() are passed from command line,
  • main() is the only function declared by the compiler and defined by the user,
  • main() is by convention a unique external function,
  • main() is the only function with implicit return 0; at the end of main(). When control crosses the ending ‘}’ for main it returns control to the operating system by returning 0 to it (if there is no explicit return statement with a return value). The OS normally treats return 0 as the successful termination of the program.
  • return type for main() is always is an int, (some compilers may accept void main() or any other return type, but they are actually treated as if it is declared as int main(). It makes the code non-portable. Always use int main().
Open and closing brasses { }
{
	////////
}

Open and closinng brasses tells the starting and ending of the statement.

What is printf?

The printf statement allows you to send output on screen and see the output of that program. that is following given bellow.

Example

#include <stdio.h>
int main()
{
    int x, y, n;
    x = 2;
    y = 5;
    n = x + y;
    printf("%d + %d = %d\n", x, y, n);
    return 0;
}
Output :

2 5 7


What is scanf()
  • The scanf function allows you to accept input from users via keyboard. which for us is generally the keyboard.
  • The scanf function can do a lot of different things, but it is generally unreliable unless used in the simplest ways.
  • It is unreliable because it does not handle human errors very well. But for simple programs it is good enough and easy-to-use.
  • "scanf" stands for "scan format", because it scans the input for valid tokens and parses them according to a specified format.
scanf("%d", &b):

The scanf function uses the same placeholders as printf

int uses %d
    float uses %f
    char uses %c
    character strings  use %s

Example of the scanf

#include <stdio.h>
 int main()
{
    int a, b, c;
    printf("Enter the first value:");
    scanf("%d", &a);
    printf("Enter the second value:");
    scanf("%d", &b);
    c = a + b;
    printf("%d + %d = %d\n", a, b, c);
    return 0;
}
Output:

a=2 b=3 c=5

Previous Home Next