Thursday, July 18, 2013

Functions in C

Functions are nothing but a piece of code which is meant to do some task out of the main program, which can be reusable. In C, we write functions to make program simple. Suppose we want to find the square of a number ten times in a program, instead of writing ten times the same code with different numbers, we can write a function which takes a number and gives the square and use the function every time we need the function.

Functions are basically of three types.

sizeof() operator in C

sizeof() operator is a unary operator used to find the size of the arrays or the size of a variable or size of structures in terms of bytes. If we use sizeof(variable), it returns the size taken by it in terms of bytes.

Syntax:
sizeof(variable_name);
Let us the application of the sizeof operator in the following example.

Storage Issues in Arrays

In arrays, we do have storage under a single name. All the array elements are assigned sequential address starting address from the index 0. Based on the data type we use, we can access the location of the index by increment of the address based on the data type we use.

Here is the table, which states the general address space used by a data type.

Wednesday, July 17, 2013

Arrays in C

Arrays are nothing but a bulk storage of a single data type in a single name. Suppose in a program, we need to store months of a year, then we take twelve different variables. Instead of taking twelve different variables and taking a risk to maintain them, we can declare all the twelve under one name i.e., months, by declaring it as an array.

An array can have any number of elements. All these elements are given an index with a subscript to the variable.

gets() as Input Function in C

In C, along with scanf(), we have another function which is widely used for taking inputs. That is gets(). But the difference between scanf() and gets() is that gets() takes only the Strings or char arrays for the input. If you observe the prototype of the gets() function, you can understand it easily.
char   *_Cdecl gets(char *__s);
You can understand more clearly if you observe the following program.

What happens if we don't use address-of in scanf

In C, while using the scanf() function, we have to specify arguments with address-of(&) operator to take the values which we give into the variables. But what happens when we don't place the address of operator? Does it return a error or works well?

Check out the following program to understand it well.

scanf() as Input Function in C

In C, the most commonly used Input Function is scanf(). This function takes the input from the standard input i.e., keyboard and sets the values taken to some variable. This scanf() function takes any type of data based on the format specifiers and then assigns the value to the variable of that particular data type when specified as arguments.

To know the prototype of the scanf() function, you can refer here.

Tuesday, July 16, 2013

puts() as Output Function in C

In C, along with printf(), we have puts() to print some text on to the screen. We can print some literal text but not the variables. Using puts(), we can't print any variable values. But can print only some text on the output.

If we observe the prototype of the function puts() in STDIO.H, we will understand the function. It will be like this

Format Specifiers in C

In C, we use the format specifiers in both the printf and scanf functions for specifying the type of the variable. Format specifiers are the part which we should be careful in using. We have to specify the exact format specifier for the data type we are using for the variable. If we don't use the appropriate one, it may result in the unexpected results.

The following table represents the most commonly needed format specifiers in C.

Printf() as Output Function in C

Printf() is the most widely used output function in C. We have used printf() for many printing operations previously. Let us know more about the printf() statement. In C, printf() has a certain format strings which define what should be output of the program.

We already know the prototype of the printf() function. If not, click here to know.

Escape Sequences in C

Escape sequences are used mostly in C and C++. It is nothing but a backslash(\) followed by a character. It is meant for doing some function in the output. They are called escape sequences because, backslash makes the C compiler to escape from the normal execution of the string and perform some function.

Here is the list of escape sequences which are generally used in C.

Input and Output Functions in C

Before going to the functions, we will first know what is Input Function and What is Output Function.

Input function is that function which is ready to take some value into the program. In C, we have many functions, but the most used Input function is the scanf().


Monday, July 15, 2013

The continue Statement in C

In C, along with the control Flow statements, there are other two statements which also controls the flow. Among them one is continue statement while the other is break statement.

While the break statement gets the flow out of a loop, continue statement makes the loop to turn to the next iteration. It doesn't break the entire loop, but just breaks the current iteration and makes the loop to move on to the next iteration.

The do... while loop in C

The do...while loop is another kind of loop in C. It is different from the other looping statements. In for loop or while loop, we check for the condition before execution of the statements. But in do... while, we perform execution first and then check for the condition. You will get clear understanding after checking the following program.

The while loop in C

In C, while loop is one of the looping statements which is used most. In while, unlike for, we need not mention the initial and increment statements. We directly specify the condition which is to be met and the loop continues to execute until that condition fails.

In some situations, while loop is better than for loop. But in most of the case, for loop is better than while.
Syntax:

  • while(condition)
  • {
  • //Statements
  • }

Sunday, July 14, 2013

The for loop in C

In the Control Flow Statements, loops are one of the most useful and necessary part. Among the loops, for loop is the most familiar and used looping statement.

Syntax:

  • for(initial; condition; Increment)
  • {
  • //Statements to be executed
  • }
The above shown is the syntax of a for loop. A for loop contains three parts mainly.

The goto Statement in C

The goto Statement is an unconditional branching statement in C. Suppose if we want to go to some set of statements in the same function immediately. Then we use goto to switch from current executing statements to the block of statements which we want to perform and the execution continues from that lines of execution.

The goto statement must have a label. A label is that which recognizes which set of statements are to be executed. Consider the following example, to understand more about the  goto statement.

What is spaghetti code

A code with more number of goto statements in C is called as spaghetti code. A spaghetti code is that which is unstructured, twisted and tingled. If we use more number of gotos, then the code is called as Spaghetti code.

Program with Increment Operators in printf()

We have observed a program on Increment Operators when assigned to variable. If not, click here.
We have clearly understand how to analyze the pre-Increment and post-Increment Operators in such a case and ho w the values are manipulated when it is such a case. But what happens when we use the same expression in printf(). Does the result is same or any change occurs?

Consider the following example,

Program on Increment Operator

Most of the people are confused every time in analyzing the Increment Operators because they actually do. We should be careful in analyzing the Pre-Increment and Post-Increment Operators.

In most of the competitive exams, we come across a problem on Increment Operators. We should be careful enough in solving the problems on Increment Operators.

Consider the following example, to understand the Increment and Decrement Operators.

Saturday, July 13, 2013

The break Statement in C

Break statement in C plays an important role in terminating the control statements. In C, we have many control statements. To get out of the statements in the middle, break is used. Break is generally used in looping statements and in the switch...case statements.

Syntax:
break;

Switch Statement with float in C

We know that Switch Statement takes only integer values for switching to cases. But what happens if we place a float value in the switch statement. Does it return a error or it executes successfully?

Consider the following example, to understand about this concept.

Friday, July 12, 2013

Switch case with char in C

We know that switch case statement works only with integer values. But what happens when we use char values?Does it return any error? Does it works?

To answer your questions, here is a program, which takes the char input and performs the switch case operation. Check out the below example and you will understand what happens.

Switch Statement in C

The switch statement is multi-decision statement which matches an expression to a set of constant values and branches to the corresponding value.

The switch case statement is placed in place of if...else if we have more number of matches to a variable.

The syntax of the switch-case statement is as shown below.

If... Else Statements in C

If...else is the first and the most widely used Control Statements in C. It is widely used because of its simplicity. If Else Statements is used in three ways. In all the three cases, it just takes some condition and perform some set of statements.

The condition we use is mostly by using the relational operators and the logical operators. We can use a single condition or multiple conditions in a single if statement.

Thursday, July 11, 2013

Control Flow in C

In C, we generally have a flow of statements which are executed step by step. They are performed in the order they are specified. Suppose if we want to execute a set of statements when a condition is satisfied, then the Control Flow comes into play.

Control Flow is nothing but controlling the flow of statements execution. In C, we have different types of Control Flow Statements.

The Comma Operator in C

Comma is generally used to separate two things. In C, along with separating two things, we also use comma as an operator along with separator.

If we use comma as an operator, then the expression evaluates to the right sub-expression.

For example,
x=(a,b);
Then x is assigned the value of b.Here parenthesis are must because comma operator has the lowest precedence than that of assignment. So parenthesis should be used to evaluate the expression.

Conditional Operator in C

Conditional Operator is a special kind of Operator which is used to check whether the condition mentioned is true or not and then perform an action based on the result. It is represented by
cond?exp1:exp2
which means, to evaluate the condition first. If the condition is true, then execute exp1, if it is false, execute exp2.

Wednesday, July 10, 2013

What happens to Operator Precedence in Compound Assignment

We know that as per the Operator precedence, the multiplication has more precedence than that of addition. Also we know that in when we write a compound assignment notation as,
x*=3, it means x=x*3;
So, when it comes to a equation like,
x*=a+b, 
What happens with the equation. How does the Operator precedence takes place. Check out the following program first,

Compound Assignment Operator in C

We know what is Assignment Operator in C. Compound assignment Operator is the advancement of Assigning. Compound assignment operator is the short notation of an operation if the operation is performed on the variable itself.

For example, 
x+=1 means x=x+1
The first notation is compound assignment where as the second notation is the notation we already know. The following table gives you more types of compound assignment Operators.

Shift Operators in C

Shift Operators are bit-wise operators used to shift the bits of a number either two the left or to the right. Based on the side which we are shifting, shift operators are classified into two types.

  1. Left Shift(<<)
  2. Right Shift(>>)
Both these Operators considers the binary representation of the number and shift the bits.

One's Complement Operator in C

This operator is a unary operator. It just takes one value and performs one's complement on the number.

For example,
x=~3;
It takes the binary representation of the 3,
3 - 0011

Tuesday, July 9, 2013

Bit-wise Operators in C

Bit-wise operators are used to perform operations on the binary value of the number. These operators can be applied only on the Integral data types i.e., short, int, long, and also on char, as it can be converted to corresponding ASCII.

These operators are used for bit-manipulation in C. Bit manipulation is done on the numbers, whether they are signed or not. There are six bit-wise operators in C. The following table gives you description of the operators.

Logical Operators in C

Logical Operators are used to perform some logical operations in C. Sometimes, we need to use more than one relational operator in C. In such cases we use this kind of logical operators to connect the relational operators.

There are three logical operators. The following table gives a description of the logical operators.

Relational Operators in C

Relational Operators are those operators, which are used to find the relation between two operands. In C we need to perform some operations to know the relation between the operands, such operators are listed under the relational operators. When we use such a operator, the result gives out to be either 1 or 0 i.e., true or false.

The below table gives a list of relational operators which we use in C.

Monday, July 8, 2013

Assigning float value to int type

In general, if we assign the integer value to the float type, it automatically converts the type to float by just adding the decimal points.

For example,
float a=3;
It takes the value as 3.000000. You can understand this by referring to the concept of Type casting by clicking here.

But what happens if we assign float to int? Does it give an error? Let us check it now.

Type Casting in C

Type Casting is nothing converting one data type value into another data type value. In C, we do have type casting where in we can convert a data type into another data type. Based on the type of conversion, we have two types of conversion.

  1. Implicit
  2. Explicit
Both these conversions are for converting one data type value into another data type but the difference lies with, whether we mention to convert or it automatically converts. Lets get more briefly into the topic.

Operator Precedence in C

In C, we perform many operations. In such operations, generally we come across a problem or ambiguity. Ambiguity means possibility of getting different answers for the same expression. We can clearly understand what is ambiguity by observing the following example,
x=3+4*5;
So, what would be the answer to the above equation. Let us solve the same equation in two different ways.

Mathematical Operators in C

Mathematical Operators are those operators through which we perform some Arithmetic operations in C. These Operators are broadly classified into two types

  1. Unary Operators
  2. Binary Operators
Both the Operators are responsible for performing the Arithmetic Operators, but they are differed based on the number of Operands they use.

Difference between Pre-Increment and Post-Increment Operators

As we already know that Unary Operators are of two types, Increment and Decrement Operators. Increment Operator is used to increment the value by one and the Decrement Operator is used to decrement the value by 1.

Again these Increment and Decrement Operators are divided into two types, pre and post. There is a lot of difference between in this pre and post. ++x comes under Pre-Increment Operator and x++ comes under Post-Increment Operator.

We can understand this difference with an example program. Consider the following program.

Sunday, July 7, 2013

Assignment Operator in C

The assignment operator is used for assigning some value to an operand or a variable. In C, the assignment operator is equal sign (=). In mathematics the significance of the equal to sign is to be sure that both the left and right values of the equal sign have the same value. But in C, its significance is somewhat different.

For example,
x=2+3;
signifies that the expression on the right is evaluated and the resulting value is assigned to the variable on the left side of the equation.

Operators in C

Operators are nothing but symbols which are used to perform some operation on the operands i.e., variables or constants.

If you consider the below example,
2+3
Here,

  • 2 and 3 are operands
  • + is an operator. 
There are four types of operators in C. They are

Return in C

Return Statement is written at the end of a subroutine to get back to the called routine. This return statement is used to return some value to the called function. In C, we use the return statement like this,
return(x) or return x;
Both the usages result the same, they return the value x;

Once a return statement is used, the function gets back to the called function and doesn't execute the lines of code under the return. So return statement is used generally at the bottom of the function.

Printf in a Printf Statement

I think most of you know what an Expression means, if not click here.

So we are moving on to the complex part of the expressions, What happens when a printf() statement is included in a expression???

Before knowing about it, we go on with a simple example of expression

x=3+(y=5+6)
Do you know what would be the result of the expression, it just gives a value of 5+6 i.e., 11 to y and the value of x would be 3+y i.e., 3+11 and the value is 14.

Expressions in C

Expressions are nothing but everything we represent. An expression can be a constant or a variable. The operations performed on these expressions are also considered to be as expressions. Based on the complexity of the expressions, they are divided into two types.

  1. Simple Expressions
  2. Complex Expressions
Expressions plays an important role in building logic to a C program. To perform some operation in C, we need to use these Expressions.

Saturday, July 6, 2013

Statements in C

In C, everything we write comes under a statement. A C program contains many number of statements. These are the building blocks of your C program.

Every Statement is ended up with a semicolon(;) except for the directives i.e., declared with the pre-processor (#).

For example,
x=2+3;
is a normal statement which adds up the values 2 and 3 and place the resulting value into the variable x.

Scanf in C

scanf() is a function in C which enables user to give some input to C program. This scanf() function is provided in the library of the C programming, in the header file "STDIO.H". This header is responsible for the Input and Output operations on C.

All the functions responsible for the Input and Output operations are present in this header file. We can see the prototypes of these functions by visiting the Include folder of the "TC" which you have installed on your computer.

If you observe a C program carefully, we do have a doubt regarding the scanf() function. C doesn't support function overloading, but scanf() takes any number of parameters we give. Did you ever have a doubt of that???

Friday, July 5, 2013

Printf with More Format Specifiers

We know that printf() function is responsible for printing something to the Output in C. Generally we write a printf() function with a string in it to be printed, or a string with format specifiers, followed by the variables which should take place of the format specifiers.

For example,


  1. #include<stdio.h>
  2. main()
  3. {
  4. int a=5;
  5. printf("Hello\n");
  6. printf("Your number is %d", a);
  7. }
For the above program, the output turns out to be as

Hello
Your number is 5

But if it has more or less number of format specifiers, then what happens???

Thursday, July 4, 2013

Printf in C

Printf() is a function in C which enables user to print some text on to the screen. This printf() function is provided in the library of the C programming, in the header file "STDIO.H". This header is responsible for the Input and Output operations on C.

All the functions responsible for the Input and Output operations are present in this header file. We can see the prototypes of these functions by visiting the Include folder of the "TC" which you have installed on your computer.

If you observe a C program carefully, we do have a doubt regarding the printf() function. C doesn't support function overloading, but printf() takes any number of parameters we give. Did you ever have a doubt of that???

Constants in C

A Constant is a data storage location used by our program like a variable. But we can't change the value of a constant during execution. There are two types of constants in C. They are

  1. Literal Constants.
  2. Symbolic Constants.

Monday, July 1, 2013

Selector in JQuery

JQuery Selectors are one of the most important part of a Jquery statement. They allow us to select particular element from the web page and perform some kind of action on them. This selection may be based on CSS selectors or based on their own custom selectors.

All the selectors are represented by $ followed by parenthesis, $().


Typedef Keyword in C

The typedef keyword is used to create a new name for the existing data type. In other words, we can say that typedef creates a synonym for the existing data type. For example,

typedef int integer;
creates integer as a synonym for integer. Hence we can use integer as a data type for the int.

Example:

integer count;

Sunday, June 30, 2013

Data Types in C

In C we have many data types and each data type has its own range and its own specialization. Here is the table which gives you details about the data types and the range of each data type we are providing.

Variable Type
Keyword
Bytes Required
Range
Character
char
1
-128 to 127
Integer
int
2
-32768 to 32767
Short Integer
short
2
-32768 to 32767
Long Integer
long
4
-2,147,483,648 to 2,147,483,647
Unsigned character
unsigned char
1
0 to 255
Unsigned integer
unsigned int
2
0 to 65535
Unsigned short integer
unsigned short
2
0 to 65535
Unsigned long integer
unsigned long
4
0 to 4,294,967,295
Single Precision floating-point Number
float
4
1.2E-38 to 3.4E38
(Approx 7 digits precision)
Double precision floating-point number
double
8
2.2E-308 to 1.8E308
(Approx 19 digits precision)

Keywords in C

A keyword is a predefined word or a reserved word for a purpose. In C language there are totally 32 keywords. All the key words and their description is mentioned in the following tabular format. Please check the following table for a better understanding of each of the keyword.


Variables in C

A variable is a named data storage location in your computer's memory. By using a variable in the program, we are just referring to the data in our memory. To use the variables in our program, we must know how to create them. In creating a variable, there are certain conditions to be followed. They are

Conditions to setting Variable Names:

  • The name can contain letters, digits and the underscore character i.e., '_'.
  • The first character of the name must be a letter or an underscore.
  • If there is any change in the case of the letters, then they are treated as two different variables i.e., count  and Count are two different variables.
  • Keywords can't be a variable.

Saturday, June 29, 2013

Program without a Main Function

We would be wondering that we can write a C program without a main function. Generally we know that a C program cannot be executed without a main function. But we can execute it without main. Just try out the code below, it works fine even without a main function in it.

#include<stdio.h>
#define decode(s,t,u,m,p,e,d) m##s##u##t
#define begin decode(a,n,i,m,a,t,e)
int begin()
{
printf(” hello “);
}

Understanding a Program in C

Let us know more about a C program. A C program contains many components. If you observe the previous example, you can identify many things. Let us know more about what they are, why we have used them and how to use them.

Consider another example of C program which contains more components, than in the previous example and know what they are.

First C Program

Now, we are moving to our first program on C. This program just illustrates you to display the message Hello world,  but along with the program, we are going to understand the structure and the way we are supposed to write the program.

Example 1:


#include<stdio.h> 
main() 
{ 
printf("Hello World \n"); 
return 0; 
}

Friday, June 28, 2013

Creating a Program in C

While creating a program, we need to follow certain steps. These are the steps to be followed while creating any kind of C program.

  • Create the source code.
  • Compile the Source code.
  • Link the compiled code to create executable.
  • Run the executable code.

Basics of C Programming

For a programming language, we generally write the program in the high level language i.e., by using alphabets, numbers and symbols. But computer understands very low level language. Hence a program must undergo many transformations to convert into machine level language.

For a C program, 
  • User writes his thoughts in the form of program, called as Source File.
  • This file is converted by the compiler into an object file.
  • This object file is then linked with a linker and gets converted into Executable program.

Introduction to C

What is C?

C is a programming language that allows a programmer to communicate with the computer. C is a flexible language and adaptable language, and it is the most used languages in the world. It is a general purpose programming language and is more convenient to use than many powerful programming languages. 

C is designed and implemented on Unix Operating Systems, by Dennis Ritchie. In today's world, there are many high level languages to choose, but C takes the top position of all because of its simplicity and flexibility.

Thursday, June 27, 2013

Structure of JQuery

JQuery Synax

JQuery, the name itself says it is querying something. It means it selects a particular HTML element and performs some action on it. Hence the syntax of a JQuery is also in that format only.

$(selector).action(), where
  • $ is for representing it as a jQuery.
  • selector represents the HTML element to be selected.
  • action() represents the kind of action we perform on the selected element.

Wednesday, June 26, 2013

Introduction to JQuery

JQuery is nothing but a modified version of Java Scripts. JQuery is easier to learn and to implement. It is a JavaScript Library. Before learning JQuery, you need to know three things.

  • HTML
  • CSS
  • Java Script
And Remember another thing, you are just writing the Java Script in another way.

Tuesday, June 25, 2013

First Post

Hello Ram,

This is a blog for yourself. This is a blog just as a guide for you all the time what you know or what you want to keep remembered regularly...

Anyways have a nice posting, and a nice collection