Showing posts with label example. Show all posts
Showing posts with label example. Show all posts

Inter Process Communication using Named Pipes - Chat Program in C

In this post, we will see a chat program using named pipes (fifo). Pipes are used for communication between processes. The named pipes are fifos. They enable two way communication unlike ordinary pipes. But they are half duplex, i.e. communication can take place only in one direction at a time. The program is in 3 parts: pipe_creation.c, leftTerminal.c and rightTerminal.c.

pipe_creation.c

#include<stdio.h>
void main()

Relational Algebra - Selection, Projection, Joins etc

The relational algebra defines a set of operations on relations, paralleling the usual algebraic operations such as addition, subtraction etc which operate on numbers.The relational algebra operations take one or two relations (tables) as input and return a relation as output. This post we discuss the following relational operations:
  1. Selection (σ)
  2. Projection (π)
  3. Cartesian product
  4. Joins

Selection Operation (σ)

Algorithm, C and C++ Programs to find Closure From Functional Dependencies

In this post we will see how to find closure of an attribute or a set of attributes. Before learning how to get closure, we should first know what is a closure. Closure of a given set C is the set of attributes that are functionally determined by the set C under the set of functional dependencies F. There can be closure for any set. Every attribute in the set whose closure is to be found out, will be a member of its closure set C+ also. Consider an example:

Storage Classes for Variables in C Programming Language

Every variable in C programming language has two properties; type and storage class. 'Type' refers to the data type of the variable such as integer, character, floating point values etc. It also deals with the size of the variable ( in bytes). 'Storage class' determines the part of memory where storage is allocated for the variable and how long the storage allocation continues to exist. It also determines the scope which specifies the part of the program over which a variable name is visible, i.e. the variable is accessible by name. The scope restriction can be overrode by making use of pointers. Whatever, in short, storage class is the property that determines the part of memory where storage is allocated, the lifetime of variable and the scope of the variable.

There are for storage classes in C programming:

  • Automatic
  • Register
  • External
  • Static

Linear Search in C and C++ Languages

Linear search simply means 'looking for an element in the whole array from one end to the other'. The searched element is compared with the first element of array first, then with the second, then with the third, so on upto the end of the array. This is time consuming when the array is pretty enough. The time complexity is highest.The C and C++ programs for linear search is given below.

C Program:

#include<stdio.h>

void main()
{

Program to Understand Bitwise Operators

This program is to understand working of bitwise operators


#include<stdio.h>

main ()

{

unsigned int a = 60; /* 60 = 0011 1100*/

unsigned int b = 13; /* 13 = 0000 1101 */

printf ("a=60 ( 0011 1100)\nb=13 ( 0000 1101)\n"); 

int c = 0;

c = a&b ; /* 12 = 0000 1100 */

printf ("a&b=%d\n",c );

c = a | b ; /* 61 = 0011 1101 */

printf ("a|b=%d\n",c );

c = a ^ b ; /* 49 = 0011 0001 */

printf ("a^b=%d\n", c );

c = ~ a; /*-61 = 1100 0011 */

printf ("~a=%d\n" , c );

c = a << 2 ; /* 240 = 1111 0000 */

printf ("a<<2=%d\n" , c );

c = a >> 2 ; /*15 = 0000 1111*/

printf ("a>>2=%d\n" , c );

}