C Programming language

C Standard Library Function

Day 1: Introduction and brief history of C Programming language

Day 1: Advantages and Disadvantages of C, C Keywords, Data type modifiers in C

Day 1: Data types in C Programming language

Day 1: Secondary data types, Primitive and Non-primitive data types

Day 1: C Variables, C Constant, Format Specifiers in C

Day 2: Write first C program

Day 2: Flow of C program with example, main(), printf(), scanf()

Day 2: Operaters in C Programming language, Arithmetic operators

Day 2: Relational operators and Logical Operators in C Programming language

Day 2: Assignment, Increments and Decrement Operators in C Programming language

Day 3: Conditional statement: if else statement in C Programming language

Day 3: Conditional statement: switch statement in C Programming language

Day 3: Jump statements: return statement in C Programming language

Day 3: Jump statements: go to statement in C Programming language

Day 3: Jump statements: break statement in C Programming language

Day 3: Jump statements: continue statement in C Programming language

Day 4: Loops OR Iteration statement in C Programming language: for Loop

Day 4: Loops OR Iteration statement in C Programming language: while Loop

Day 4: Loops OR Iteration statement in C Programming language: do while Loop

Day 5: Array in C Programming language

Day 5: Access elements of Array in C Programming language

Day 5: One dimensional Array representation in memory using C Programming language

Day 5: Two dimensional Array representation in memory using C Programming language

Day 5: Multidimensional Array in C Programming language

Day 6: Function in C Programming language

Day 6: Definition, Declaration and Calling a Function in C Programming language

Day 6: Passing array to a function in C Programming language

Day 6: Calling Function in C Programming language : Call by value

Day 6: Calling Function in C Programming language : Call by reference

Day 6: Recursive Function in C Programming language

Day 6: Adding function to the library in C Programming language

Day 7: Pointer in C Programming language, How to use Pointer, Pointer declaration

Day 7: NULL Pointers in C Programming language

Day 7: Array of Pointers in C Programming language

Day 7: Pointer arithmetic in C Programming language

Day 7: Pointer to Pointer in C Programming language

Day 7: Pointer to Function in C Programming language: Passing pointers to functions

Day 7: Pointer to Function in C Programming language: Return pointer from functions

Day 8: Strings in C Programming language, Declaring String in C Programming language

Day 8: String functions in C Programming language

Introduction of Structure

Accessing the members of Structure

Structure With typedef Keyword and Use of sizeof function

Example of Structure

Dynamic memory allocation in C: Introduction

adplus-dvertising
Day 1 C Constant, C Variables, Format specifiers in C
Previous Home Next

C constants

Constants also called a literals. Constant refer to fixed values that the program may not alter. constant can be any of the basic data types. C have a two type of constant:

  1. Numeric constant
  2. Character constant

C constant is showing in the figure:

Variables

A variable is a meaningful name of data storage location in computer memory. When using a variable you refer to memory address of computer.

Types of variables In C variable are divided in two types

  1. Global variable: global variable is a variable defined outside any function block. Global variable is also called external variable.
  2. Local variable: local variable is a variable defined inside a function block. Local variable is also called automatic variables.

Variable Declaration Examples

Single declarations


int age;
float amount;
char last;

Multiple declarationsYou can repeat the the declaration line with a different variable on each line .


int age;
int hrNumber;

But the normal way is to separate the variables by a comma. Although not required the names are easier to read if a space follows the comma.


int age, HouseNumber, quality;
float distance, Discount;
char first, second;

Scope of variables

The scope of a variable depends on where it is declared.

  • The area of the program where that variable is valid, i.e. the parts of the program that have access to that variable. This is determined by the location of the declaration.
  • The life span of that variable, i.e. the length of time that the variable remains in memory.
Where do you Declare Variables

Variables can be declared as

  • Prior to the start of the main( ) function.
  • Within the main function, after the opening {
  • Within a function after the opening {
  • Within a block of code, after the {
  • Global or external variable Declared before the start of the main( ) function.

Static Variable

When static is used with a global variable it indicates that the variable is local to the current file. If the programmer would like the value of the variable to be remembered when the function is revisited then that variable must be declared as static.

Example


static int aVariable = 1;

In the example the initialisation to 1 occurs only on the first execution of this line of code, it is disregarded on further executions of the line.

static has a different meaning when used with global variables.

Format Specifiers in C
%cThe character format specifier.
%dThe integer format specifier.
%iThe integer format specifier (same as %d).
%fThe floating-point format specifier.
%eThe scientific notation format specifier.
%EThe scientific notation format specifier.
%gUses %f or %e, whichever result is shorter.
%GUses %f or %E, whichever result is shorter.
%oThe unsigned octal format specifier.
%sThe string format specifier.
%uThe unsigned integer format specifier.
%xThe unsigned hexadecimal format specifier.
%XThe unsigned hexadecimal format specifier.
%pDisplays the corresponding argument that is a pointer.
%nRecords the number of characters written so far.
%%Outputs a percent sign.
Previous Home Next