×
In life, NO ONE and NOTHING will help you until you start helping YOURSELF.
--Your friends at LectureNotes
Close

Problem Solving And Programming In C

by Vineeth Babu
Type: NoteDownloads: 121Views: 1317Uploaded: 7 months agoAdd to Favourite

Touch here to read
Page-1

Problem Solving And Programming In C by Vineeth Babu

Topic:
Vineeth Babu
Vineeth Babu

/ 341

Share it with your friends

Suggested Materials

Leave your Comments

Contributors

Vineeth Babu
Vineeth Babu
1.typedef struct{ char *; nodeptr next; } * nodeptr; what does nodeptr stand for? ans: 2.int *x[](); means ans:expl: Elments of an array can't be functions. 3.struct list{ int x; struct list *next; }*head; the struct head.x =100 Ans: above is correct / wrong expl: Before using the ptr type struct variable we have to give memory to that .And also when ever the struct variable is ptr then we access the members by "->" operator. 4. main() { int i; i=1; i=i+2*i++; printf(%d,i);} ans: 4 5.main() { FILE *fp1,*fp2; fp1=fopen("one","w") fp2=fopen("one","w")
fputc('A',fp1) fputc('B',fp2) fclose(fp1) fclose(fp2)} a.error b. c. d. ans: no error. But It will over writes on same file. *****n 6.#include<malloc.h> char *f() {char *s=malloc(8); strcpy(s,"goodbye");} main() { char *f(); printf("%c",*f()='A');} o/p=? for strcpy function string.h header file should be included semicolon is missing in strcpy function leftside function call can come when it is returning some pointer so *p=’A’; 7. #define MAx(x,y) (x)>(y)?(x):(y) main() { int i=10,j=5,k=0; k= MAX(i++,++j); printf("%d %d %d ",i,j,k); } ans. 12 6 11 8. main() {
int a=10,b=5, c=3,d=3; if (a<b)&&(c=d++) printf(“%d %d %d %d”, a,b,c,d); else printf("%d %d %d %d”, a,b,c,d); } ans: 10 5 3 3 Note: if condition should be in braces 9. main() { int i = 10; printf(" %d %d %d \n", ++i, i++, ++i); } ans: 13 11 11 10. main() { int *p, *c, i; i = 5; p = (int*) (malloc(sizeof(i))); printf("\n%d",*p); *p = 10; printf("\n%d %d",i,*p); c = (int*) calloc(2); printf("\n%d\n",*c); } Note: calloc function has less parameters calloc(n, elemsize) main() { int *p, *c, i; i = 5; p = (int*) (malloc(sizeof(i))); printf("\n%d",*p);
*p = 10; printf("\n%d %d",i,*p); c = (int*) calloc(2,2); printf("\n%d\n",*c); } ans: garbage, 5, 10, 0 (malloc gives garbage and calloc initializes with zeros) 11. #define MAX(x,y) (x) >(y)?(x):(y) main() { int i=10,j=5,k=0; k= MAX(i++,++j); printf("%d..%d..%d",i,j,k); } ans: 12 6 11 12. main() { enum _tag{ left=10, right, front=100, back}; printf("left is %d, right is %d, front is %d, back is %d",left,right,front,back); } ans: left is 10, right is 11, front is 100, back is 101 13. main() { int a=10,b=20; a>=5?b=100:b=200; printf("%d\n",b); } ans: lvalue required for ternary operator 14. #define PRINT(int) printf("int = %d ",int) main()

Lecture Notes