Question No: 7 (a) Ans:
Null Pointer
A Null Pointer is a pointer that does not point to any memory location, instead pointer is initialized either with NULL or 0 explicitly to indicate that this pointer variable is still unused. And it is a standard practice to use a NULL constant rather than 0.

Example of Null Pointer
#include < stdio . h>
void main()
{
  int *p = NULL; //initialize the pointer as NULL
  printf("The value of pointer is %u",p);
}

Output:
The value of pointer is 0.

Next Question
#include < stdio.h >

int main()
{
  if(!NULL)
  {
  printf("C programming is easy");
  }
  else
  {
  printf("C programming is not easy");
  }
}

Output:
C programming is easy

Discussion
According to C Coding standards,

NULL is the pointer whose value is equivalent to 0 (Zero).
And 0 (Zero) value is FALSE in C and other non-zero value is TRUE.

Hence if !(not operator) is applied to NULL (FALSE), it implies that !NULL is TRUE
So, if block statement is executed and "C programming is easy" is printed.

Q.No.5 (a). Ans:

//Program to find the largest word in a given sentence.

#include< stdio.h >
#include< stdlib.h >

void main()
{
  system("cls");
  char a[100];
  int i,lenght = 0,count = 0, max = 0,beg;

  printf("Enter any string ");
  gets(a);

  for(i=0;a[i]!='\0';i++)
  {
    lenght++;
  }

  for(i=0;i<=lenght;i++)
  {
    if(a[i] == ' ' || a[i] == '\0')
    {
        if(count > max)
        {
        max = count;
        beg = i - max;
        }
        count = 0;
    }
    else
    {
    count++;
    }
  }

  printf("\n");

  for(i=1;i<=max;i++)
  {
  printf("%c",a[beg]);
  beg++;
  }
}

Output:
Enter any string : Khwopa Engineering College

Largest word = Engineering

Question No. 8. Ans:

//Displaying the detail of all employees in the order of their salary.

#include< stdio.h >
#include< stdlib.h >

struct employee
{
char name[20];
int id;
int salary;
};

void main()
{
  struct employee e[5],temp;
  int i,j;
  FILE *fp;
  fp = fopen("employee.txt", "r+b");

  fread(&e, sizeof(e), 5, fp);

  for(i=0;i<5;i++)
  {
    for(j=0;j<5;j++)
    {
    if(e[i].salary < e[j].salary)
        {
        temp = e[i];
        e[i] = e[j];
        e[j] = temp;
        }
    }
  }
  printf("Required record of employee in order of their salary are \n");

  for (i = 0; i<5; i++)
  {
  printf("%s %d %d\n", e[i].name, e[i].id, e[i].salary);
  }

  fclose(fp);
}

Output:
Required record of employee in order of their salary are
Satis 1 20000
Utshab 2 30000
Nimesh 3 40000
Safal 4 50000
Biraj 5 60000



Question From: 2075 Ashwin
Web hosting by Somee.com