Name-Prabhjot Bawa Class-A6005 Roll - No.-A09 Submittedto-Mr - Chandra Parkash

You might also like

Download as doc, pdf, or txt
Download as doc, pdf, or txt
You are on page 1of 8

Name-prabhjot bawa Class-a6005 Roll.no.-a09 Submittedtomr.

Chandra parkash
Ans.1=> when we using MACRO,Control never leaves the home function : it just makes the function a longer.

Example: #include<stdio.h> #include<conio.h> float square(float x); main() { float c,d; printf(enter the value of c ); scanf(%f,&c); d=square(c); printf(The value of d is %f,d); getch(); } float square(float x) { float y; y=x*x; return(y); }

ANS. 2) Multi file programs can be made by making one function as library function and by using it as it is in another files without defining it.

#include <stdio.h> #include<conio.h> int x; double fact; int main()

{ for (x = 0; x <= 20; ++x) { printf("factorial of %d = %d",x, factorial(x)); } return 0; }

Ans3. No, in c language we donot have any case for limiting the size of a an array ,data enterd within a substrict exceeding the array size will simply be placed outside the memory. #include<stdio.h> void main() { int arr[33],y; for(y=0;y<=66;y++) scanf(%d,&arr[y]); getch(); }

Ans4.YES IT IS TRUE. An array data structure is a data structure consisting of a collection of elements OF EACH DATA TYPE. Its elements involves a single subscript which can either represent a row or column index. Pointers are variable address to memory location.* is used to declare a pointer and & signed is used to store the address of the variable where the value is stored. It is not necessary that address of the variable will be in the sequence i.e, address of different variable will be scattered in the memory.

Ans 5 #include<stdio.h>

#include<conio.h> main() { int a; for(a=1;a<10;a++) { printf("enter the number"); scanf("%d",&a); if(a==1) printf("ONE"); if(a==2) printf("TWO"); if(a==3) printf("THREE"); if(a==4) printf("FOUR"); if(a==5) printf("FIVE"); if(a==6) printf("SIX"); if(a==7) printf("SEVEN"); if(a==8) printf("EIGHT"); if(a==9) printf("NINE");

getch(); }

} Ans.6 String library functions are those that can be used to carry out many of the string manipulations and following are the string library functions:#include<stdio.h> #include<conio.h> #include<string.h> void main() { char ch[],st[]=prabhjot; int len; clrscr(); printf(enter the string); scanf(%s,&ch); len=strlen(ch); printf(length of the string,len); printf(reverse of the string is,strrev(ch)); len=strcmp(st,ch); printf(duplicate of the string %d,len); getch(); } Ans.7Structure Pointer:- We have a special pointer variable that points to structure variable that pointer is called as structure pointer. #include<stdio.h> #include<conio.h> main() { struct book { char name[10];

char author[15]; int pages; }; struct book b1={xyz,bawa,100} struct book *ptr; ptr=&b1; printf(\n%s%s%d,b1.name,b1.author,b1.pages); printf(\n%s%s%d,ptr->name,ptr->author,ptr->pages); getch(); } A Structure to pointer: #include <stdio.h> #include <string.h> #include <stdlib.h> struct student { int id; char name [100]; struct student * next; }; void printStudents(struct student *p) { printf("Printing the list of students \n"); for (p; p != NULL; p=p->next) printf ("id=%d name=%s \n",p->id,p->name); printf("\n"); } int main () { struct student *p, *head, *mid, *tail; p=(struct student *) malloc (sizeof(struct student)); p->id=12; strcpy(p->name,"Tom"); p->next=NULL; head=p; tail=p; p=(struct student *) malloc (sizeof(struct student)); p->id=7; strcpy(p->name,"Bob"); p->next=NULL; tail-> next=p; tail=p; mid=p; p=(struct student *) malloc (sizeof(struct student)); p->id=9; strcpy(p->name,"Rob"); p->next=NULL; tail-> next=p; tail=p;

printStudents(head); printStudents(head); return 0; }

Ans.8 The memory occupied by a union and a structure with same element is not always same. In structure, each element has its own storage location, whereas all the elements of the union use the same location. Union may contain many members of different types, it can handle only one member at a time. If structure is struct book { char name[10]; int pages; };

0
If union is union item { int m; float x; char c; }code;

0 is for char, 1 is for slack byte and 2 & 3 are for

int.

This declares a variable code of type union item. The union contains three members, each with a different data type. However, we can use only one of them at a time. This is due to the fact that only one location is allocated for a union variable, irrespective of its size.
1007 1009 1011 1013

1000 is for char c, 1001 is for int m, 1002 & 1004 are for float x.

You might also like