C programs may be written without regard to the spacing of source code. The C compiler accepts program with any layout.
Newlines
C permit a new line to be started at any point in text that is displayed with printf. To begin a new line of output you have to use a backslash \ and a lowercase letter n. This combination of characters is the symbol called newline.
#include
main()
{
/* main */
printf("Subhajit is trying to instill \n");
printf("C programming techniques in me");
} / * main */
And now the program displays two sentences, each on a seperate line:
Subhajit is trying to instill
C programming techniques in me
Alternatively, the same program can be written as shown below to generate the same output
#include
main()
{
/* main */
printf("Subhajit is trying to ");
printf("instill \nC programming techniques in me");
} / * main */
Variables
Variable is a place to store information. Information stored in a variable can be recalled later in the program by using the name of the variable. A variable name must
- begin with a letter
- uses only letters and digits in the name
- the first 8 characters are unambiguous
There may be some difference in the way different C compilers treat variables. Remember that an underscore is a letter and punctuation marks aren't accepted in a variable name.
Assignment
Information is stored in a variable by assigning value to it.
e.g c=5;
It indicates that the value 5 has been assigned to the variable c.
printf
printf is used to display an integer. %d is a symbol employed to display the integer. The proper syntax is
printf(" Value of c is %d\n", c);
define
A constant number can be referred to by a special name in a C program.
# define NUM1 2
# define NUM2 4
Programmers use uppercase letters to define a constant which is used in a C program for the sake of convenience so that there is no confusion between variables and constants.
include# and #define are compiler directives.
1/06/2001