Thursday, July 18, 2013

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.

Tuesday, July 16, 2013

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.

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.

Sunday, July 14, 2013

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.

Monday, July 8, 2013

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.

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

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.

Saturday, July 6, 2013

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???

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???

Monday, July 1, 2013

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

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.