Wednesday, 8 October 2014

More on C pointers

Initialize a pointer

Before you can use a pointer in for instance a printf statement, you have to initialize the pointer.
The following example will not initialize the pointer:


 #include<stdio.h>

 int main(void) {
  int *ptr_p;
  printf("%d\n",*ptr_p);
                return 0;
 }


How to use C pointers in C ??

To make full use of the C Programming language, you have to have a very good understanding of pointers. For most people it will take some time to fully understand pointers. So be patient. You have to learn pointers because they are used everywhere in the C language. Once you master the use of pointers, you will use them everywhere. OK, enough pep talk, let’s start.

Tuesday, 7 October 2014

Download Ebook of "Introduction to information retrieval "

Download Turbo C (full screen) for windows xp , 7 , 8 , 8.1

Download " MCQs in computer science by Timothy j Williams"

Download "The C Programming language by Brian W Kernighan and Dennis M Ritchie"

Download Let us C by yashwant kanetkar

How to Use C Structures, Unions and Bit Fields with Examples

Structures, Unions and Bit fields are some of the important aspects of C programming language.
While structures are widely used, unions and bit fields are comparatively less used but that does not undermine their importance.
In this tutorial we will explain the concept of Structures, Unions and Bit fields in C language using examples.

Write a C Program to Calculate the Trace and Normal of a Matrix

Trace of Matrix                                                                                              Normal of Matrix


Trace: Trace of a Matrix can be defined as the sum of the main diagonal elements.
Normal: Normal can be defined as the square root of the sum of squares of all the elements of a Matrix.


#include<stdio.h>
#include<conio.h>
void main()
{
int i , j , n ;                                       /* 'i' used for Rows and 'j' used for Columns */
int Row , Column;
int Matrix[9][9];
float trace , sum , normal;

clrscr();
trace = 0;
sum = 0;

printf(" Enter the order of Matrix\n");
scanf("%d * %d" , &Row , &Column);

printf(" Enter the elements of Matrix\n");
for(i=0 ; i<Row ; i++)
{
for(j=0 ; j<Column ; j++)
{
scanf("%d" , &Matrix[i][j] );
}
}

                                                  /* Trace and Normal */

for(i=0 ; i<Row ; i++)
{
for(j=0 ; j<Column ; j++)
{
if(i==j)
{
trace + = Matrix[i][j];                   /* It can also be Written as  trace=trace+Matrix[i][j]  */
}
sum + = pow( Matrix[i][j] , 2 );       
}
}
normal = sqrt(sum);

printf(" Trace = %f\n" , trace);
printf(" Normal = %f\n" , normal);
getch();
}                                                               /* End of main() */

Detailed overview of C Language Functi

Functions: 
Function is a set of instructions to carry out a particular task. The Function after processing returns a single value.
In other word, we say a Function is a group of statements that can perform any particular task. 

Types of functions:
Types of Functions

WAP to determine whether the Number is Prime or Not by using while and if Statement

C break Statement
Break Statement: 
There are many situations where we want to jump out of a loop instantly. The keyword break allows us to do this. When break is encountered inside any loop, control automatically passes to the first statement after the loop. So Let us understand the break statement with the help of Program :-

Write a C Program to Print the Multiplication of Two Matrices

Multiplication of Matrix
Statement of C Program: This Program accepts two Matrices of different or same order and Find the product of these Matrices and prints the Product Matrix:

Condition: The Column of First Matrix must be Equal to the Row of the Second Matrix.

Write a Program to check a number it is Armstrong or not by using while and if Statement


Armstrong Number

Armstrong Number:
  • Three Digit Armstrong Number defined as the Sum of cubes of its Digit is equal to the Number Itself.
  • Armstrong Number is also known as Narcissistic Number.
  • Example: 153 = (1*1*1) + (5*5*5) + (3*3*3)

C Program For Fibonacci Series upto 100 by using while Statement



Fibonacci_Series
Fibonacci Series:
  • Fibonacci Series is the Series in which Next Number is Sum of Previous Two Numbers.
  • Example: 0 1 1 2 3 5 8 13 21 34 ............and so on.

Most Important Differences Between C And C++

Relationship b/w C and C++

How to Crack a Job interview Successfully

Job Interview

To have a successful interveiw and to make a lasting impression, the Body Language is very important. Postures and body movements are unconsious forms of expression and therefore they have a language of their own. We are unaware of our gestures and body movements most of the time, but other people can notice our gestures and movements if they pay attention and know what they mean.
                                                        An important thing to be noted here is that body language applies not only to the Interviewer but also to the Interviewee. Also, note that these gestures may happen throughout the conversion or a discussion and they change as the conversation progresses.


Interview Skills

The objective of paying attention to nonverbal communication is to help you change the direction of the conversation. If the person is showing negative gestures; then you need to change the topic by asking a new questions or talking about something else.

Multidimensional Arrays

The array we used in the last example was a one dimensional array. Arrays can have more than one dimension, these arrays-of-arrays are called multidimensional arrays. They are very similar to standard arrays with the exception that they have multiple sets of square brackets after the array identifier. A two dimensional array can be though of as a grid of rows and columns.
#include <stdio.h>

const int num_rows = 7;
const int num_columns = 5;

int
main()
{
  int box[num_rows][num_columns];
  int row, column;

  for(row = 0; row < num_rows; row++)
    for(column = 0; column < num_columns; column++)
      box[row][column] = column + (row * num_columns);

  for(row = 0; row < num_rows; row++)
    {
      for(column = 0; column < num_columns; column++)
        {
          printf("%4d", box[row][column]);
        }
      printf("\n");
    }
  return 0;
}
This will produce following result:
   0   1   2   3   4
   5   6   7   8   9
  10  11  12  13  14
  15  16  17  18  19
  20  21  22  23  24
  25  26  27  28  29
  30  31  32  33  34
The above array has two dimensions and can be called a doubly subscripted array. GCC allows arrays of up to 29 dimensions although actually using an array of more than three dimensions is very rare.

Command Line Arguments

It is possible to pass arguments to C programs when they are executed. The brackets which follow main are used for this purpose. argc refers to the number of arguments passed, and argv[] is a pointer array which points to each argument which is passed to mainA simple example follows, which checks to see if a single argument is supplied on the command line when the program is invoked.
#include <stdio.>h
main( int argc, char *argv[] )  
{
   if( argc == 2 )
      printf("The argument supplied is %s\n", argv[1]);
   else if( argc > 2 )
      printf("Too many arguments supplied.\n");
   else
      printf("One argument expected.\n");
}
Note that *argv[0] is the name of the program invoked, which means that *argv[1] is a pointer to the first argument supplied, and *argv[n] is the last argument. If no arguments are supplied, argc will be one. Thus for n arguments, argc will be equal to n + 1. The program is called by the command line:
$myprog  argument1
More clearly, Suppose a program is compiled to an executable program myecho and that the program is executed with the following command.
$myeprog aaa bbb ccc
When this command is executed, the command interpreter calls the main() function of the myprog program with 4 passed as the argc argument and an array of 4 strings as the argv argument.
argv[0]         -  "myprog"
argv[1]  -  "aaa"
argv[2]  -  "bbb"
argv[3]  -  "ccc"

Sunday, 5 October 2014

Self Destructing program in C

This program will destroy itself upon execution. The program will cause the .exe file to be deleted upon execution. That is this program is capable of destroying itself upon execution. Here is the code
#include<stdio.h>
#include<conio.h>
#include<dos.h>

Will the following code result in memory leak?

#include<stdio.h>

void main(void)
{
    char *ptr = (char*)malloc(10);

    if(NULL == ptr)
    {
        printf("\n Malloc failed \n");
        return;
    }
    else
    {
        // Do some processing
    }

    return;
}
Answer: Well, Though the above code is not freeing up the memory allocated to ‘ptr’ but still this would not cause a memory leak as after the processing is done the program exits. Since the program terminates so all the memory allocated by the program is automatically freed as part of cleanup. But if the above code was all inside a while loop then this would have caused serious memory leaks.