Upload
student
View
41
Download
4
Embed Size (px)
Citation preview
LOGIC DEVELOPMENTCONTROL FLOW ANALYSIS & C BASICS
1.FIND THE PATTERN!
• n = input (“Enter a positive integer”) • while n > 0
• c = n • while c > 0
• print n • c = c – 1
• end• n = n - 1 • print newline
• end
Ans : 1
• Input : n=5;• Output:• 55555• 4444• 333• 22• 1
2.FIND THE OUTPUT!
• int main() { • int a[5] = {5, 1, 15, 20, 25}; • int i, j, m; • i = ++a[1]; • j = a[1]++;• m = a[i++]; • printf("%d, %d, %d", i, j, m);• return 0;
• }
Ans : 2
• OUTPUT : 2,2,3
• Solution:• A[1]=1;• A[1]=2;• i=2;• J=2• A[1]=3;• i=3• M=A[3]=15
3.FIND THE OUTPUT!
• int main() { • int i = 1; • switch(i) {
• printf("Hello\n"); • case 1: printf("Hi\n");
• break; • case 2: printf("\nBye\n");
• break;
• }• return 0;• }
Ans : 3
• OUTPUT: Hi• Solution: Switch uses concept of label;
4.FIND THE OUTPUT!
• int main() { • char str[]="C-program";• int a = 5;• printf(a >10?"Ps\n":"%s\n", str);• return 0;
• }
Ans : 4
• OUTPUT : C-program
5.FIND THE OUTPUT!
What will be the output of the program (sample.c) given below if it is executed from the command line?cmd> sample monday tuesday wednesday thursday/* sample.c */ #include<stdio.h> int main(int argc, char *argv[]) { while(--argc>0) printf("%s", *++argv); return 0;}
ANS : 5
• OUTPUT :
6. What does fp points to?
• int main() { • FILE *fp; • fp=fopen("trial", "r");• return 0;
• }
ANS : 6
7.FIND THE OUTPUT!
• int main() { • char str[] = "peace";• char *s = str; • printf("%s\n", s++ +3); • return 0;
• }
ANS : 7
• OUTPUT : ce
8.FIND THE OUTPUT!
• int main() { • int *p; • p = (int *)malloc(20); • printf("%d\n", sizeof(p)); • free(p); • return 0;
• }
ANS : 8
• OUTPUT : 4
9.FIND THE OUTPUT!
What will be the output of the program (sample.c) given below if it is executed from the command line?cmd> sample friday tuesday sunday/* sample.c */ #include<stdio.h> int main(int argc, char *argv[]) { printf("%c", *++argv[2] ); return 0; }
ANS: 9
• OUPUT : u• SOLUTION: argv[2]= Tuesday
• ++ argv[2] =uesday;• %c of ++argv[2] = u
10.FIND THE OUTPUT!
• int main() { • short int i = 0; • for(i<=5 && i>=-1; ++i; i>0)
• printf("%u,", i); • return 0;
• }
11.FIND THE OUTPUT!
• int main() { • int y=128; • const int x=y; • printf("%d\n", x); • return 0; • }
ANS : 11
• OUTPUT : 128
12.FIND THE OUTPUT!
• int main() { • struct emp {
• char n[20]; • int age;• };
• struct emp e1 = {"Dravid", 23};• struct emp e2 = e1;• if(e1 == e2)
• printf("The structure are equal");• return 0;
• }
ANS :12
• OUTPUTS NOTHING;• Error occurs at run time..! Struct data structures cannot be
compared using ‘==‘ Operator
13.FIND THE OUTPUT!
• int main() { • printf(5+"IndiaBIX\n"); • return 0;
• }
ANS : 13
• OUTPUT : BIX