- 1 Basic for C programming
- 2 Why C is called a system programming language?
- 3 What are subroutines in C?
- 4 Variables and constants
- 5 Numeric variables
- 6 Character variables
- 7 Writing a simple C program
- 8 What are literals and identifiers in a programming language?
- 9 Input and output function
- 10 Syntax of a printf() function
- 11 What is a main() in c program?
- 12 How to comment in a c program?
Basic for C programming
C is a general-purpose programming language, which was designed by Dennis Ritchie. C is not a very high-level language, so it will be little difficult to understand, when compared with a high-level language like python, if you are planning to learn C++, C#, and Java then it will be better to start with C because C++, C#, and Java are based on C.
Why C is called a system programming language?
C is called a system programming language because it is useful for writing compilers and operating system’s
What are subroutines in C?
C functions are called subroutines.
Structure of a c program
Function 1 ()
Variables and constants
Variable is a box which stores the values and it would always better to use meaningful names so that you can reduce confusion in the code with names. Variables should be declared before we use in C
The numeric variables which we can use in C are
(1) Integer values
(2) Floating point values
In C, we can use four modifiers
With numeric variables, we can also use this four modifiers
(a, A ,b,B) : Alphabets
(#,!,&,@): special symbols
Declaring variables initializing variables
Int student_num; student_num =24;
Float marks; marks =97;
Char name; name = Tom;
Note: variables has to be declared before use
Constant variable: constant is variable whose values does not change, which are used for fixed values such as pi=3.14;
Writing a simple C program
What are literals and identifiers in a programming language?
In programming language constants are called literals and variables are called identifiers, also constant is box whose values are fixed, while the variable is a box whose values can be changed.
Input and output function
Scanf () function receives input values while printf() function print output values on the screen
Syntax of a printf() function
Printf(“<format string>”,<no of variables>);
<format string> contain
Int uses %d
Float uses %f
Char uses %c
Character string uses %s
We use scanf() in order to receive input values from user
Note: the difference between printf() and scanf() function is that we use address operator (&) before variable in scanf()
What is a main() in c program?
It is a function, which you can consider as a vessel with a set of statements in it.
The data type int kept before main() because the function will return an integer number also due to the fact that, the main() function always return an integer number.
How to comment in a c program?
Comments in a c program must be enclosed within asterisk(*)
/* this is a comment*/