Friday, 21 July 2017

Explain the difference between text mode and binary mode files



Streams can be classified into two types: 

1. text streams and
2. Binary streams

1.Text streams are interpreted, with a maximum length of 255 characters. With text streams, carriage return/line feed combinations are translated to the newline n character and vice versa.

2. Binary streams are uninterrupted and are treated one byte at a time with no translation of characters. a text stream would be used for reading and writing standard text files, printing output to the screen or printer, or receiving input from the keyboard. A binary text stream would typically be used for reading and writing binary files such as graphics or word processing documents, reading mouse input, or reading and writing to the modem.

Wednesday, 19 July 2017

Difference between Structure and Union


Sr No.
Structure
Union

1
Structure is user defined data type
Which store a record with multiple value
Union is also a user defined data type
But only one member can be saved at a time
2
Separate space was allocated for each member of structure
A common space allocated for all member

3
All members can be initialized at ones.
                                                                   
Only one member can be initialized at a time.

4
Total memory allocated by a structure variable is equal to number of member allocated space.
Space allocated equal to higher member allocated space.
5
One can provide and used all member data simultaneously.
Only one member value can be read or write at ones.
6
Uses rate of structure is higher due to separate space allocation for each member.
Uses rate is lower than structure due common space allocation.


7
You can updated previous value of any member without losing other member data
If a member initialized and another attempt for change value of other member lead loss of previous value.
























#include<stdio.h>
struct stu
{
     int roll;
     char nm[10];
     char city[10];
};
union emp
{
     int roll;
     char nm[10];
     char city[10];
};
void main()
{
     struct stu ob1;
     union emp ob2;
     clrscr();
     ob1.roll=101;
     strcpy(ob1.nm,"Girfa");
     strcpy(ob1.city,"Student Help");
     printf("\nSize of Structure %d",sizeof(ob1));
     printf("\n\tRoll=%d\n\tName=%s\n\tCity=%s",ob1.roll,ob1.nm,ob1.city);
     ob2.roll=101;
     printf("\nSize of Union\t %d",sizeof(ob2));
     printf("\nUnion Roll %d",ob2.roll);
     strcpy(ob2.nm,"Girfa");
     printf("\nValue Loss due to Union  %d",ob2.nm);
     getch();
}

Difference Between Union and Enum

Union 


Union is user defined data type which is use to store a data member from more than one data member. Followings are some key point about union
  • Union is also a user defined data type But only one member can be saved at a time
  • A common space allocated for all member
  • Only one member can be initialized at a time.
  • Space allocated equal to higher member allocated space.
  • Only one member value can be read or write at ones.
  • Uses rate is lower than structure due common space allocation.
  • If a member initialized and another attempt for change value of other member lead loss of previous value. 
#include<stdio.h>
union emp
{
     int roll;
     char nm[10];
     char city[10];
};
void main()
{
     union emp ob2;     

     ob2.roll=101;
     printf("\nSize of Union\t %d",sizeof(ob2));
     printf("\nUnion Roll %d",ob2.roll);
     strcpy(ob2.nm,"Girfa");
     printf("\nValue Loss due to Union  %d",ob2.nm); 
}

Enum

Enumerate is user defined data type which is integer value assign to a data member as its options. Enumerate is useful to provide user friendly name for available integer options used as some setting of application. For example if an application has shown available color to its window by integer number as we have seen in dos color command.

So for change color you need to remember color code which increase complexity. By using enumeration you provide color name in user friendly mode.
i.e.  Color.Red,Color.Blue instead of integer code. System will find the correspondence integer related to given color by enumeration definition.

Saturday, 15 July 2017

Greatest Number from array using Pointer

Q : Write a program using pointer to find greatest number in an array.

Solution : 

#include<stdio.h>
#define MAX 5
void main()
{
     int ar[MAX],*pt,h,i;
     for(i=0;i<MAX;i++)
     {
          printf("Enter Number>> ");
          scanf("%d",&ar[i]);
     }