Академический Документы
Профессиональный Документы
Культура Документы
1) Comments in C
2) Program Style, Round one, format specifiers
3) Variable, identifiers or Names in C and CONSTANTS IN C
4) Working with variable, identifiers or Names in C etc
Why use Comments
• Documentation of variables, functions and their usage.
• Explaining difficult section of code.
• Describes author, program, data, modification changes and
revisions.
• Best programmers comment as they write the code not after the fact.
Comments
• The addition of comments inside programs is desirable.
• These may be added to C programs by enclosing them as follows.
/* This code will not be compiled and executed*/
• Note that /*opens the comment field and
• */ closes the comment field
• Comments may span multiple lines
• Comments may not be nested one inside the another
• For example /* and /* and */ */ error generated.
Program Style, Round one, format specifiers
Printing Numbers
void main(void)
{
printf(“This is the number two:%d”,2);
}
Format specifier
Printing Strings
void main(void)
{
printf(“%s is %d million miles from sun”, “venus”,67);
}
o/p
venus is 67 million miles from sun
Printing Characters
void main(void)
{
printf(“The letter %c is ”, ‘j’);
printf(“pronounced %s”, “jay”);
}
o/p
The letter j is pronounced jay
Variable
Identifiers or Names in C
• Identifiers in C must begin with a character or underscore
and may be followed by any combination of characters,
underscores or digits 0-9.
Example
summary exit_flag
Jerry7 Number_of_moves
Rule
Variables in lower case
Constant in upper case
void main(void)
{
int num; //variable declared
num=2; // variable assigned value
printf(“This is number two:%d”,num);
}
• All variables must be defined to specify their
name and set aside storage.
%c Single character.
%s String.
%d Signed Decimal Integer.
%f floating point(decimal notation).
%e floating point(exponential notation).
%u unsigned decimal integer.
%x unsigned hexadecimal (uses “abcdef”).
%o unsigned octal integer.
Escape Sequences
Escape Sequence Character
\a Bell (speaker beeps)
\b Backspace (non-erase)
\f Form feed/clear screen
\n New line
\r Carriage Return
\t Tab
\v Vertical tab
\\ Backslash
\? Question mark
\' Single quote
\" Double quote
\xnn Hexadecimal character code nn
\onn Octal character code nn
Working with variable
#include<stdio.h>
#include<conio.h>
void main(void)
{
int first,second,third;
first=10;
second=10;
third=10;
}
Working with variable