I guess after reading the program, many things are clear to most of the people. Now, I would like to move your focus on the double backslash ( //), which plays an important role while writing complex programs in C language.
We humans are in a habit to keep a note of everything, which remind us to keep a follow-up of all the things we need to keep a track off. In the same way, C gives us flexibility to put a comment at any place where there is a possibility of confusion. Now, following are few useful tips to write a comment.
- There are two formats to write a comment in C lang. They are as follows:
a) put double backslash ( // ) in every line before the starting of the comment.
For example: // C lang is cool
// I am learning C lang just for fun
OR b) enclose a comment within /* */.
Start a comment with a single backslash with an asterick ( /* ) and then at the end of the
comment put an asterick with a single backslash ( */ ). A comment can be split over
more than one line. for e.g.
/* My
name is
Samiha */
- We can add any number of comments in a single program. But they cannot be nested.
For example: /* C lang /* is very easy */ */ - ( It is Invalid)
I hope a simple way of adding a comment to your program will help you to make your program user friendly & this will save your time to get the hold of the program whenever you try to figure out what the program does.
Wednesday, May 21, 2008
Comments in 'C' lang
Labels:
Comments
Tuesday, May 13, 2008
Q & A Session contd...
Question 3: What is printf() function?
Answer: printf() is a function defined in stdio.h library file and is used for printing output on the standard output device which is Monitor. This function takes 2 parameters:
1. The format string
2. The Variable
e.g.
printf("%d",num);
Here %d is the format string used, the format string tells the compiler which type of data needs to be shown on the standard output device. Some of the format specifiers are:
%d for integer values
%c for character values
%s for strings
%f for float values (these are the values with decimal point e.g 123.45)
Variable is the memory location in the primary memory where we store the value.
For more on printf() visit the links available.
Question 4: What is scanf() function?
Answer: scanf() is used for reading input from the standard input device which is keyboard. This function takes 2 parameters:
1. The format string
2. The address of the variable where the value will be stored.
e.g. scanf(“%d”, &num);
%d is used to tell the compiler that the value to be read is an interger value and the other parameter &num tells the compiler the memory location to put the value in. The “&” operator is used for accessing the address of a defined variable.
Some of the format specifiers are:
%d for integer values
%c for character values
%s for strings
%f for float values (these are the values with decimal point e.g 123.45)
For more on scanf() visit the links available.
Answer: printf() is a function defined in stdio.h library file and is used for printing output on the standard output device which is Monitor. This function takes 2 parameters:
1. The format string
2. The Variable
e.g.
printf("%d",num);
Here %d is the format string used, the format string tells the compiler which type of data needs to be shown on the standard output device. Some of the format specifiers are:
%d for integer values
%c for character values
%s for strings
%f for float values (these are the values with decimal point e.g 123.45)
Variable is the memory location in the primary memory where we store the value.
For more on printf() visit the links available.
Question 4: What is scanf() function?
Answer: scanf() is used for reading input from the standard input device which is keyboard. This function takes 2 parameters:
1. The format string
2. The address of the variable where the value will be stored.
e.g. scanf(“%d”, &num);
%d is used to tell the compiler that the value to be read is an interger value and the other parameter &num tells the compiler the memory location to put the value in. The “&” operator is used for accessing the address of a defined variable.
Some of the format specifiers are:
%d for integer values
%c for character values
%s for strings
%f for float values (these are the values with decimal point e.g 123.45)
For more on scanf() visit the links available.
Subscribe to:
Comments (Atom)