Posts

Showing posts from June, 2019

Tips and Tricks for declaring Variables

Tips and Tricks for declaring variables Declaring variables is not a easy task. It is a difficult and mind confusing task. So here, I am providing some tips that can help you to declare variables easily in C Programming. Always try to follow following points : 1. Every variable name must start with a letter(a-z , A-Z) or a underscore( _ )  2. Never start a variable name with numbers,symbols,etc 3. A variable should not contains special characters like $  < * & ^ % #, etc 4. A variable can contain only digits,letters(it may be upper case or a lower case),underscore 5. Variables must be realistic and connected to real life problem, for example if you are writing a        program for calculating total marks of student then use the variables like total_marks,etc 6. Do not use short,letter names. for example, to store student total marks don't use the variables like a,b,f,m,etc. they are confusing names.  7. Avoid too much long names. 8. Yo

sizeof() Operator | Sizes ,Precision and Range of different data types

sizeof() Operator This operator is used to find out size of variables,structures ,pointers ,etc in bytes. Program to understand sizeof() opertaor #include<stdio.h> #include<conio.h> void main() { int x,y; x=98; clrscr(); y=sizeof(x); //size of variable printf("%d",y); getch(); } See Output NOTE - We will use this operator in further posts and program to understand it more. Program to find out size, precision and range of different data types #include<stdio.h> #include<limits.h> #include<float.h> void main() { clsrcr(); printf("sizeof(char)=%u\n",sizeof(char)); printf("sizeof(short)=%u\n",sizeof(short)); printf("sizeof(int)=%u\n",sizeof(int)); printf("sizeof(long)=%u\n",sizeof(long)); printf("sizeof(float)=%u\n",sizeof(float)); printf("sizeof(double)=%u\n",sizeof(double)); printf("sizeof(long double)=%u\n",s

Programs to Understand C fundamentals

Program to understand fundamenals Escape Sequence #include<stdio.h> #include<conio.h> void main() { clrscr(); printf("feel_the_coder\n"); // \n is the escape sequence printf("Subscibe Us\a"); // \a is also a escape sequence for a audible/visible alert printf("Give me space\t"); // \t is escape sequence and moves cursor to next horizontal tab getch(); } See Output Operators #include<stdio.h> #include<conio.h> void main() { int a,b,c; // variables a=10; b=5; c=a+b; clrscr(); if(a==10||b==6) // OR operator printf("%d",c); if(a==10&&b==5) // AND operator printf("%d",c); if(a!=b) // NOT operator printf("%d",c); getch(); } Note - if() is a conditional statement which you will study in subsequent posts. See Output Literals #include<stdio.h> #include<conio.h> void main(){ int x=5; float v=5.98; clrsc

Environment For C | Program Development Steps

Image
Environment for C Some steps are involved in developing a c program which are as followed - 1. Program Creation 2. Program Compilation 3. Program Execution UNIX/LINUX  Environment                                                       1. Program Creation  * In UNIX C file can be created using vi editor as- $ vi filename.c * You can save this file by using ESC key and SHIFT+zz key. 2. Program Compilation * Program created in first step can be compiled using following command as- $cc filename.c * If your program contains mathematical operations the compile it as- $cc filename.c -lm * Compiled file which can be used for execution is stored in the file a.out * If you want your file to saved with specified name then compile it as follows-\ $cc filename.c -o executablename 3. Program Execution  * Executable file can be executed by following command- $ a.out  or $ executablename NOTE - $ is the unix prompt also know