Posts

Endianness

Image
Endianness: Programmers who work on high level languages they don’t think about the hardware endianness or computer architectures; they only think about the code and the executable part and not how to convert little endian to big endian or vice versa. But we should know how to deal with endianness; as sometimes it plays an important role and can create problem when transmitting from one computer and receiving on another whose endianness differ. When communicating between computers, if the endianness differs of that two(computers), the data transmitted can’t be received in the actual form. What is Endianness? Endianness refers to the byte order in which data is stored in the memory; also describes the byte order sent over a digital link. The term may also be used more generally for the internal ordering of any representation . The endianness is categorized into two types: Little endianness Big endianness Note : It is hardware dependent. Little Endianness: In this...

Data Types in C

Image
 Introduction: There are two types of data: constants and variables. Constants is the data that cannot be changed once assigned; Variables data type is the data which can e changed whenever required. Data is of four types: int real char string Syntax for declaring variable: Note: When we declare variable, memory will be allocated to the variable but it contains “garbage value” (in case of auto variable) Default variables are signed. If we declare it as well as initialize it, it is known as “Initialization”             Example:               int a =Declaration               int a=10; = Initialization  Rules for constructing integer constants: Integer constant must contain one digit It must not have a decimal digit or value It can be positive or negative; if no sign mentioned default considered as positive. No commas and blanks are allowed in betw...

Errors in C Language

Image
Errors are categorized  into two type: Warnings Errors 1. Warnings: Warnings, which indicate a potential problem, but still let your code compile. Warnings are sort of future bugs that will appear at runtime i.e. We might get undesired output even the inputs and the code are properly crafted. The modern compilers mostly generate the warnings and still compile your code till the executable file; the modern compilers automatically detect the problems and solve it on its own if it is small. Example: In this example below, we haven’t included the string library and still using string based predefined function in the program; the program will execute in this case but warning will come as “include <string.h> or provide a declaration for strlen ()”   To avoid warning:  You must include proper header files in the program. In above case, include string-based functions header file i.e. Write #include<string.h> before main (). 2. Errors: Types of er...

Compilation Stages for C Program

Image
Compilation process: Compilation is a process of converting human readable code into machine understandable code Compilation process is divided into 4 stages/parts: Pre-processor stage Translator stage Assembler stage Linker stage 1. Pre-processor stage First stage of compilation process. In this stage we will get pure C file or extended c file from our source file.         Pre-processor stage is responsible for: Including header files. Remove comments. Replace macros. Do conditional compilation. 2. Translator stage In this stage the code is converted into assembly language.        Translator tasks are: To generate assembly code. Check for any syntactical error. 3. Assembler stage: In this stage the assembly language code is converted into machine understandable code or object code. The content of object file is in binary format, to make this file readable you will have to disassemble it. 4. Linker stage: L...

Basic Structure of C Program

Image
 Structure of C Program: // single line Comments # pre-processor directives prototype declarations global variables main() function { local variable declaration statements ------      --------    ------- } user_defined_function1() { variable declaration statements -----         -----         ----- } Explanation: 1. Comments: Comments can be places anywhere in the program; generally used for documentation purposes or to increase the readability of the code. There are two types of comments 1. Single line comments        2. Multi line comments Single line comments starts with // followed by statement ex: // this is a single line comment Multi line comment start with /* and ends with */. ex: /* This is           multi line           comment */ 2. Preprocessors Directives:...

Getting started with C Language (2)

Image
Introduction: There are 2 nature of data: Constant and Variable 1)      Constants are the data that cannot be changed (example: PI is constant i.e. 3. 1418..) 2)      Variable is the nature of data that can be changed wherever required throughout the program. In any program we do lot of calculations. the results of these calculations need to stored in computer memory to retrieve these values when required in program. for easy retrieval and usage of these values the names are given to the memory cells called as variable names. Rules for constructing integer constants: Integer constant must contain one digit It must not have a decimal digit or value It can be positive or negative; if no sign mentioned default considered as positive. No commas and blanks are allowed in between the digits of number The integer range can be stored is -2147483648 to +2147483647 or -32768 to +32767 (depends on compilers) Valid integer constants: 400 -555 3089 -4096 ...

Getting started with C Language (1)

Character set in C language: Character set denotes the alphabets, digit or special symbol used to represent information. Alphabets A, B, C, ----, Z a, b, c ----, z Digits 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 Special Symbols ~ ` ! @ # $ % ^ & * ( ) _ - + = | \ { } [ ] ; : ” ’ < > , . ? / Raw code : It is a code which can run without OS. example: .hex code(as it deployed in 8051 and it does not contain OS) Executable code : it is a code which cannot run without OS, OS is needed for this type of code. example: C code. Compilers: Compilers convert human readable code into binary code or machine understandable code. Types of compilers: Native compiler Cross compiler Native compiler: The compiler working in one environment and generating machine understandable code for same environment is called as native compiler. Example: Turbo C, Dev C++, etc. Cross compiler: The compiler working in one environment and gener...