Learning To Program - Bing A Better Programmer (Episode - 3)
Write Comments
Looking at the title, many people may think that I write comments on Facebook. What is it again in C programming?
The fact is that sometimes large programs have to write down what you're doing. So that later you can remember what actually happened. It is not part of the program. Just for your memory or for easy understanding later. But it's a compiler! There is no place to write separately here?
Actually, there is no need to write separately. 😛 Like whatever you write after giving /* it won't compile until you give */. This is called comments in a programming language.
#include<stdio.h>
main()
{
/*we will print now */
printf(“I am a C programmer”);
}
If you compile the line, you will see that the line we will print now will not appear in the output.
Conversion Characters
To understand conversion characters, you need to understand strings. In short, a string is a collection of characters or words.
A conversion character is a placeorderplaceholder that tells us which string to put. We will now look at a program that uses conversion characters.
main()
{
printf(“%s is a good boy\n”);
}
What this line implies is that any word or any text is a good boy. Now if we introduce a new string like this,
main()
{
printf(“%s is a good boy\n”, “Rahim”);
}
Now the output will be like Rahim is a good boy.
That is, it appears that %s is replaced by Rahim. Now if there is another %s what will happen in this line?
main()
{
printf(“%s is a good boy %s \n”, “Rahim”, “I have ever seen”);
}
The second %s will sit in the output I have ever seen
It is better to say that this %s is only for strings. For text, word, etc. But it may be that we are using numbers?
main()
{
Printf(“Bangladesh won by %d runs”, “67”);
}
The output will be like this, Bangladesh won by 67 runs
%d This applies only to integer numbers. If you bring a decbutal here, the result will show wrong.
If we want to keep a decimal number then %f should be written.
main()
{
Printf(“Bangladesh won by %f runs”, “67.5”);
}
Impress everyone with the magic of PowerPoint!
Many important tasks can be accomplished using PowerPoint!😁
Data type:
The variable declaration requires data type according to the data value. There are basically four types of data types.
- char
- int
- float
- double
Character:
In C programming, the char data type is used to declare the char type to work with the character type or alphabet. The char keyword is used to declare a variable of type char.
For example char ch;
int:
The int data type is used to declare a variable of type int to work with integers. The int keyword is used to declare a variable of type int.
For example int x;
float:
The float data type is used to declare a variable of type float to work with decimal numbers. The float keyword is used to declare a variable of float type.
For example: float y;
double:
The double data type is used to declare a variable of type double to work with large numbers with decimal signs. The double keyword is used to declare a variable of type double.
For example double z;
Data Type Declare:
Declaring a data type means declaring a variable of a specific data type. Format of variable declaration of any data type:
DataTypeName VariableName;
Example: Char ch; int x;
Variables:
A variable refers to the name or address of a memory location. When working with data in the program, a variable has to be used for each data. They are called variables because their position can change.
That is, a variable can hold only one data at a time. There are roughly five types of variables used in the C language.
- Numeric variable
- Array variable
- Pointer variable
- String variable
- Custom Variable.
Declare Variables:
To work with any data in the program, you must first declare variables with the data type, in the case of C programs, all variables at the beginning of main() or other functions; The data type must be declared with
But remember that two or more variables cannot be declared in the same function.
Example of variable declaration:
main()
{
int age;
float marks;
…
}
Now a whole number can be used for age and a decimal fraction for marks.
age=25;
marks=23.8;
See the program below;
#include<stdio.h>
int main()
{
int age;
age=27;
printf(“I am %d years old”, age);
}
What comes out of the output? If it's wrong, get the error. 😉
No comments