Posts

Variable

                            1.6 VARIABLE We so many times come across the term “variable” .we assume them in math’s for solving some Equation . so let see what is the meaning of variable in programming . in c programming variable are Simple names used to refer to some location in memory that hold a value with which we are working . Syntax for declaration of variable:    data type   variablename : #include <stdio.h> int main(){ int firstNumber, secondNumber, sumOfTwoNumbers;     printf("Enter two integers: "); // Two integers entered by user is stored using scanf() function     scanf("%d %d", &firstNumber, &secondNumber);  // sum of two numbers in stored in variable sumOfTwoNumbers     sumOfTwoNumbers = firstNumber + secondNumber;     // Displays sum          printf("%d + %d = %d", firstNumber, secondNumber, sumOfTwoNumbers);  return 0; } der a small situation   we have to add 2 numbers so we have to write a

Basic input, output and variables

1.5 Basic Input, Output and Variables Let’s learn about Input and Output in our programs along with variables. There are many ways by which an input may be taken into the program, keyboard, mouse or touchscreen! Here we only deal with the keyboard and use the included “ stdio.h ” file which provides us the basic input-output functions. For now, remember that functions are bunch of instructions written for the sake of using it multiple times when necessary. So, as the function “ printf() ” or any which is defined in the file “ stdio.h ” which is included in our program, we can use “ printf() ” anywhere necessary. Similarly, “ scanf() ” is a function which can take input from the keyboard and is defined in “ stdio.h ”. But where will you store the input took from “ scanf() ” ? You’ll store all kind values or the inputs from the user in the memory and a simple way to do this is by storing them in Variables . In simple terms variables are certain names given to a particular kin

Data Types in C

Image
1.4 Data types    As in our daily languages we have different alphabets, numbers and special characters, in C we have many “data types”. These could be defined as the fundamental blocks by which define how any form of data is to be stored and processed. These data types may be different based on compilers, but in general C data types are classified into fundamental, derived and programmer-defined data types. C programming basic data types Fundamental data types are namely void, int, float, char, long, double, * (pointer type). Derived data types include arrays, string and structures. Programmer defined data types include Structure, Union and Enumerations. Let’s keep it short and define only the essential ones as you’ll have separate tutorials on some data types. 1.     Int:  This data type indicates integer numbers and it is represented by “ int ” keyword in C. Integers consume storage space of 2 bytes and range from -32,768 to 32,768. 2.     Long: This data t

What are C tokens ?

Image
1.3 What is a token? In our world when someone says token we think of an object that represents something else for example It may the receipt was given by the shopkeeper to you. But in c programming, it is the smallest unit or text which cannot be divided into a smaller unit. C token are divided as Let see them one by one Keywords We can say them reserved words because they have some special meaning in c compiler. These words cannot be used as an identifier. C language uses the following keywords: Auto Double Int Struct Break Else long Switch Case Enum register Typedef Char Extern return Union Etc. we will see them afterward. Identifier These are the name you use for a variable, functions in your program. You can begin naming a character or an underscore followed by any character or number.  Uppercase and lowercase letters are not equivalent in C, so the two id

Our First Program in C

1.2   Basic Program Let’s start here with a basic program which is so famous that is used in every beginner tutorial. We are going to discuss Hello World program. This prints (writes) “Hello World” onto the screen. #include <stdio.h> int main() {   printf( “Hello World” );   return 0 ; } The program above can be written in any text editor but has to be saved with the extension ‘ .c ’. Then the program must be compiled and run for the outcome. You’ll learn more about these processes in the previous tutorial. For now, when this program is compiled and run it’ll print “Hello World” onto the screen. Codeblocks is an IDE (Integrated Development Environment) which does all the above processes of writing, compiling and running code in one go. Now let’s take a look at the code. The first line of this C code is called preprocessor directive. These lines start with “ # ” and are, as the name suggests; directions to the preprocessor . This line says to include a file

Process of compilation

Image
1.2 Process of Compilation    Let see how actually code flow in the system before execution. At first, the code (high-level language) is given to preprocessor then the preprocessor converts that to pure High-level language (when we write a c program the starting lines contain Preprocessor directives, the preprocessor removes the preprocessor directives statements by including the file. This called as file inclusion.)    Then the compiler will take the purely high-level language and converts it into assembly language. Let see what happens in compiler and how it works In previous topic (1.1) we discuss what is programming and we touched the topic compiler.  From the previous topic, we have learned that either a computer code is compiled or interpreted nowadays. The main aim of a compiler is to convert or translate code from one language to another language.  Mainly high-level language (Human Readable) to low-level language (Machine Language) . A compiler can be cla

C Programming series Intro

Image
1.1 Introduction to Programming  C Programming is at the root of every machine, as it is used in most of the OS kernels, Embedded Machines etc.  C programming is highly favored by beginners who are learning to code. First let’s understand what programming is and how to do it. Programming by definition means to give specific instructions to the computer for performing a task. This task may be simple as printing something onto the screen or complex calculations.  Electronic devices work only with binary system i.e. 0 or 1 also called bits. So each pixel you see onscreen to each input you enter by keyboard or mouse are in the form of series of bits. As an electronic machine works only by this system you can only use binary number system to give instructions i.e. to program any machine. In fact, the early machines were given instructions to perform the tasks in the same binary language. But the problem with programming with binary code was that it was so difficult to learn and