1
Jumping Statements in C
• break is a keyword of C language.
• It is used to transfer the control of program out of switch or looping
statement.
#include<stdio.h>
int main()
{
int i;
for(i=1;i<=5;i++)
{
if(i==3)
break;
printf(“n%d”,i);
}return(0);
}
2
continue
• continue is a keyword of C language.
• It is used with looping statements. It is reverse of break statement.
• The continue statement forces the loop to continue or execute the next
iteration.
• When the continue statement is executed in the loop, the code inside the
loop following the continue statement will be skipped and the next
iteration of the loop will begin.
• #include<stdio.h>
int main()
{
int i;
for(i=1;i<=5;i++)
{
if(i==3)
continue;
printf(“n%d”,i);
}return(0);
} 3
goto
• goto is a keyword of C language.
• It is used to transfer the control of program from one part of program
to another part of program.
• It can be used anywhere in a program.
• goto statement can be used in two ways:
• Forward goto
• In forward goto statement, the label exists after the goto statement
• Backward goto
• In backward goto statement, the label exists before the goto statement.
4
Forward goto Backward goto
#include<stdio.h>
int main()
{
printf(“nwelcome”);
goto end;
printf(“nHi”);
end:
printf(“nBie”);
return(0);
}
#include<stdio.h>
int main()
{
int a;
scanf("%d",&a);
k:printf("%dn",a);
a++;
if(a<3)
goto k;
return 0;
}
5
Revision Questions
Q1 What is the output of the following source code?
#include<stdio.h>
int main()
{
int n;
for (n = 9; n!=0; n--)
printf("n = %d", n--);
return 0;
}
6
Revision Questions
Q2 What is the output of the following source code?
#include <stdio.h>
int main()
{
int i = 0;
switch (i)
{
case '0': printf("CU");
break;
case '1': printf(“AU");
break;
default: printf("CU-AU");
}
return 0;
7
Revision Questions
Q3 What is the output of the following source code?
#include <stdio.h>
int main()
{
int i;
for (i = 1; i != 10; i += 2)
printf(“ MST 2 ");
return 0;
}
8
Revision Questions
Q5 find the output
#include<stdio.h>
int main()
{
int i = -5;
while (i <= 5)
{
if (i >= 0)
break;
else
{
i++;
}
printf(“ C PROGRAMMING");
}
return 0;
} 9
Revision Questions
Q4 Predict the output of the below program:#include <stdio.h>
int main()
{
int i = 3;
switch(i)
{
printf("Outside ");
case 1: printf(“Case 1");
break;
case 2: printf(“case 2");
break;
defau1t: printf(“default");
}
return 0;
}
10
Revision Questions
Q6 #include <stdio.h>
int main()
{
int i = 3;
while (i--)
{
int i = 100;
i--;
printf("%d ", i);
}
return 0;
}
11
Revision Questions
Q7 #include <stdio.h>
int main()
{
int x = 3;
if (x == 2);
x = 0;
if (x == 3)
x++;
else x += 2;
printf("x = %d", x);
return 0;
}
12
Revision Questions
Q 8 #include<stdio.h>
int main()
{
int a = 5;
switch(a)
{
default:
a = 4;
case 6:
a--;
case 5:
a = a+1;
case 1:
a = a-1;
}
printf("%d n", a);
return 0;
} 13
Revision Questions
Q9 What is the output of C Program.?
int main()
{
while(true)
{
printf("RABBIT");
break; }
return 0;
}
14
Revision Questions
Q10 What is the output of C Program.?
int main()
{ int a=5;
while(a==5)
{
printf("RABBIT");
break;
}
return 0;
}
15
Determine output:
main()
{
int i = abc(10);
printf("%d", --i);
}
int abc(int i)
{
return(i++);
}
16
What will be printed when this program is
executed?
int f(int x)
{
if(x <= 4)
return x;
return f(--x);
}
void main()
{
printf("%d ", f(7));
}
17
Revision Questions
Q11 What is the output of C Program.?
int main()
{ int a=5;
while(a=123)
{
printf("RABBITn");
break;
}
printf("GREEN");
return 0; }
18
Revision Questions
Q 12 What is the output of C Program.?
int main()
{
int a=5;
while(a >= 3);
{
printf(“TEDDYn");
break;
}
printf(“BEAR");
return 0;
}
19
Revision Questions
Q14 What is the output of C Program.?
int main() {
int k;
for(printf(“Hello "); printf(“CSE "); printf(“STUDENTS "))
{
break;
}
return 0;
}
20
Revision Questions
Q15 What will be the output of the following code?
#include <stdio.h>
int main()
{
int i = 0, j = 0;
while (i<5,j<10)
{
i++;
j++;
}
printf("%d %d", i, j);
}
21
Revision Questions
Q16 What will be the output of the following code?
int main()
{
int a = 0;
while(a++)
{
printf(“C programming");
}
return 0;
}
22
Revision Questions
Q17 What will be the output of the following code?
int main()
{
while(1);
{
printf("C Programming");
}
return 0;
}
23
Revision Questions
Q18 What will be the output of the following code?
int main()
{
int i,j,count;
count=0;
for(i=0; i<5; i++);
{
for(j=0;j<5;j++);
{
count++;
}
}
printf("%d",count);
return 0;
}
24
Revision Questions
Q19 What will be the output of the following code?
int main()
{
int i,j,k,count;
count=0;
for(i=0;i<5;i++)
{
for(j=0;j<5;j++)
{
count++;
}
}
printf("%d",count);
return 0;
}
25
Revision Questions
Q20 What will be the output of the following code?
int main()
{
int i,j;
for(i = 0,j=0;i<5;i++)
{
printf("%d%d--",i,j);
}
return 0;
}
26
Revision Questions
Q 21 What will be the output of following program ?
#include <stdio.h>
void main()
{
char cnt=0;
for(;cnt++;printf("%d",cnt)) ;
printf("%d",cnt);
}
27
Revision Questions
Q 24 What will be the output of following program ?
#include <stdio.h>
void main()
{
int tally;
for(tally=0;tally<10;++tally)
{
printf("#");
if(tally>6)
continue;
printf("%d",tally);
}
}
28
Revision Questions
Q 25 What will be the output of following program ?
#include <stdio.h>
void main()
{
int cnt=1;
do
{
printf("%d,",cnt);
cnt+=1;
}while(cnt>=10);
printf("nAfter loop cnt=%d",cnt);
printf("n");
}
29
Revision Questions
Q 27 What will be the output of following program ?
int main()
{
int a = 0;
while(a++);
{
printf("Cpp");
}
return 0;
}
30
Revision Questions
Q 28 What will be the output of following program
int main()
{
int i;
for(i = 0,i<5,i++)
{
printf("Hello");
}
return 0;
}
31
Revision Questions
Q 29 What will be the output of following program ?
#include <stdio.h>
void main()
{
int k = 0;
for (k)
printf("Hello");
}
32
Revision Questions
Q 30 What will be the output of following program ?
#include <stdio.h>
int main()
{
int i = 0;
for (; ; ;)
printf("In for loopn");
printf("After loopn");
}
33
Revision Questions
Q 31 What is output of below program?
int main()
{
for(; ;);
for(; ;);
printf("Hello");
return 0;
}
34
What is an Array in C language.?
A) A group of elements of the same data type.
B) An array contains more than one element
C) Array elements are stored in memory in continuous or contiguous
locations.
D) All the above.
35
An array index starts with value
A) 0
B) -1
C) 1
D) 2
36
int main()
{
int a[ ];
a[4] = {1,2,3,4};
printf("%d", a[0]);
}
a) 1
b) 2
c) 3
d) Compiler Error
37
If the two strings are identical, then strcmp() function returns
A. -1
B. 1
C. 0
D. None
38
Base address of an array represents the
a) Address of last element of an array
b) Address of second element of an array
c) Address of first element of an array
d) Number of elements
39
Array elements are always stored in ________ memory locations.?
a) Sequential
b) Random
c) Sequential and Random
d) None of the above
40
What is the output of this program?
void main()
{
int a[8] = {1,2,3,4,5};
printf("%d", a[5]);
}
A. 5
B. 6
C. 0
D. Garbage Value
41
#include <stdio.h>
int main()
{
char s1[] = "Hello";
char s2[] = "Hello";
if(s1 == s2)
printf("Same");
else
printf("Not Same");
return 0;
}
• A. Not Same
• B. Same
• C. Compilation Error
• D. None of the above
42
What is the output of this program?
#include<stdio.h>
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;
}
43
What will be the output of the program ?
#include<stdio.h>
#include<string.h>
int main()
{
char str1[20] = "Hello", str2[20] = " World";
printf("%sn", strcpy(str2, strcat(str1, str2)));
return 0;
}
44
45
46
What will be the output of the following code?
void main()
{
int a[10];
printf("%d %d", a[-1], a[12]);
}
47
Which of the following correctly accesses the seventh element stored
in arr, an array with 100 elements?
A. arr[6]
B. arr[7]
C. arr{6}
D. arr{7}
E. None of these
48
• Which of the following function is more appropriate for reading in a
multi-word string?
A. scanf()
B. printf()
C. gets()
D. puts()
49
REVISION Questions
Predict output of following program
int main()
{
int i;
int arr[5] = {5};
for (i = 0; i < 5; i++)
printf("%d ", arr[i]);
return 0;
}
50
REVISION Questions
Q7 What is the output
int main()
{
int bus[3][] = {6,5,4,3,2,1};
printf("%d %d", bus[0][0], bus[2][1]);
return 0;
}
51
REVISION Questions
Q9 find the output
int main()
{
char str1[]=“CU";
char str2[20];
str2= str1;
printf("%s",str2);
return 0;
}
52
REVISION Questions
Q10 What is the output?
int main()
{
char str[25];
scanf("%s", str);
printf("%s",str);
return 0;
}
//input: New Delhi
53
#include<stdio.h>
int add(int a,int b=12)
{
return a+b;
}
int main()
{
int c ;
c=add(1,2);
printf("%d",c);
}
54
#include<stdio.h>
int add(int a,int b)
{
return a,return b;
}
int main()
{
int c ;
c=add(1,2);
printf("%d",c);
}
55
#include<stdio.h>
int add(int a,int b)
{
return a,b;
}
int main()
{
int c ;
c=add(1,2);
printf("%d",c);
return 0;
}
56
REVISION Questions
Find the output
void main()
{
int a;
printf("COUNT=");
a=show();
printf("%d", a);
}
int show()
{
return 15;
return 35;
}
57
Rohan writes the code for a function that computes the sum of n natural
numbers of the inputted number n.
int sum_n(int n)
{
if(n==1)
return 1;
else
missing statement
}
Fill in the missing statement.
58
• Sam is writing a code which has a function which calls itself. Which
programming concept is Sam using?
• The values passed to a function at the time of function calling are
knows as______________
• If we have to write a program to print first n natural ,which loop is
ideal?
59
Predict the Output of following C program ,if line 2 will be removed?
#include<stdio.h>
int add(int,int);//line 2
int add(int a,int b)
{
int sum=a+b;
return sum;
}
int main()
{
printf("%d",add(1,2));
return 0;
}
60
REVISION Questions
Q2 Find the output
int main()
{
int a[][] = {{1,2},{3,4}};
int i, j;
for (i = 0; i < 2; i++)
for (j = 0; j < 2; j++)
printf("%d ", a[i][j]);
return 0;
}
61
REVISION Questions
Q4 What is the output ?
int main()
{
char marks={'A','B','C'};
printf("%c", marks[0]);
}
62
REVISION Questions
Q16 What is the output?
63
21#include<stdio.h>
int main()
{
char str[7] = "IndiaRock";
printf("%sn", str);
return 0;
}
64
Revision Questions
Q 23 What will be the output of following program ?
#include < stdio.h >
int main()
{
int tally=0;
for(;;)
{
if(tally==10)
break;
printf("%d ",++tally);
}
return 0;
}
65
What is the output of C Program.?
int main()
{
int k, j;
for(k=1, j=10; k <= 5; k++)
{
printf("%d ", (k+j));
}
return 0;
}
66
find the output
#include<stdio.h>
int main()
{
int i = -5;
while (i <= 5)
{
if (i >= 0)
break;
else
{
i++;
continue;
}
printf(“ C PROGRAMMING");
} return 0; }
67
Revision Questions
Q 22 What will be the output of following program ?
#include <stdio.h>
void main()
{
int i=1;
while (i<=5)
{
printf("%d",i);
if (i==5)
goto print;
i++;
}
}
fun()
{
print:
printf("includehelp.com");
}
68
What is the output of C Program.?
int main()
{
int a=32;
do
{
printf("%d ", a);
a++;
if(a > 35)
break;
}while(1);
return 0;
}
69
void main()
{
printf(5+"Good Morningn");
}
A. Good Morning
B. M
C. Good
D. Morning
E. None of these
70
Let x be an array. Which of the following operations is/are illegal?
a) ++x
b) x+1
c) x++
d) x*2
71
What is the output of this program?
#include <stdio.h>
int main()
{
int arr[5] = {1,2,3,4,5};
int p, q, r;
p = ++arr[1];
q = arr[1]++;
r = arr[p++];
printf("%d, %d, %d", p, q, r);
return 0;
}
72
Guess the output.
#include<stdio.h>
int main()
{
int a[8] = {1,2,[4]=7,8,9};
for(int i=0;i<8;i++)
printf("%d ",a[i]);
}
73
# include <stdio.h>
int main()
{
char str1[] = “Chandigarh";
char str2[] = {‘c’,’h’,’a’,’n’,’d’,’I’,’g’,’a’,’r’,’h’};
int n1 = sizeof(str1)/sizeof(str1[0]);
int n2 = sizeof(str2)/sizeof(str2[0]);
printf("n1 = %d, n2 = %d", n1, n2);
return 0;
}
74
• Which loop is faster in C Language, for, while or Do While.?
• a) for
• b) while
• c) do while
• d) All work at same speed
75
Revision Questions
Q 26 What will be the output in given input?
• When, input: 'a' and 1
int main()
{
int n,i=0;
while(scanf("%d",&n)==1)
{
printf("ENDn");
}
return 0;
}
76

UNIT 2 LOOP CONTROL.pptx

  • 1.
  • 2.
    Jumping Statements inC • break is a keyword of C language. • It is used to transfer the control of program out of switch or looping statement. #include<stdio.h> int main() { int i; for(i=1;i<=5;i++) { if(i==3) break; printf(“n%d”,i); }return(0); } 2
  • 3.
    continue • continue isa keyword of C language. • It is used with looping statements. It is reverse of break statement. • The continue statement forces the loop to continue or execute the next iteration. • When the continue statement is executed in the loop, the code inside the loop following the continue statement will be skipped and the next iteration of the loop will begin. • #include<stdio.h> int main() { int i; for(i=1;i<=5;i++) { if(i==3) continue; printf(“n%d”,i); }return(0); } 3
  • 4.
    goto • goto isa keyword of C language. • It is used to transfer the control of program from one part of program to another part of program. • It can be used anywhere in a program. • goto statement can be used in two ways: • Forward goto • In forward goto statement, the label exists after the goto statement • Backward goto • In backward goto statement, the label exists before the goto statement. 4
  • 5.
    Forward goto Backwardgoto #include<stdio.h> int main() { printf(“nwelcome”); goto end; printf(“nHi”); end: printf(“nBie”); return(0); } #include<stdio.h> int main() { int a; scanf("%d",&a); k:printf("%dn",a); a++; if(a<3) goto k; return 0; } 5
  • 6.
    Revision Questions Q1 Whatis the output of the following source code? #include<stdio.h> int main() { int n; for (n = 9; n!=0; n--) printf("n = %d", n--); return 0; } 6
  • 7.
    Revision Questions Q2 Whatis the output of the following source code? #include <stdio.h> int main() { int i = 0; switch (i) { case '0': printf("CU"); break; case '1': printf(“AU"); break; default: printf("CU-AU"); } return 0; 7
  • 8.
    Revision Questions Q3 Whatis the output of the following source code? #include <stdio.h> int main() { int i; for (i = 1; i != 10; i += 2) printf(“ MST 2 "); return 0; } 8
  • 9.
    Revision Questions Q5 findthe output #include<stdio.h> int main() { int i = -5; while (i <= 5) { if (i >= 0) break; else { i++; } printf(“ C PROGRAMMING"); } return 0; } 9
  • 10.
    Revision Questions Q4 Predictthe output of the below program:#include <stdio.h> int main() { int i = 3; switch(i) { printf("Outside "); case 1: printf(“Case 1"); break; case 2: printf(“case 2"); break; defau1t: printf(“default"); } return 0; } 10
  • 11.
    Revision Questions Q6 #include<stdio.h> int main() { int i = 3; while (i--) { int i = 100; i--; printf("%d ", i); } return 0; } 11
  • 12.
    Revision Questions Q7 #include<stdio.h> int main() { int x = 3; if (x == 2); x = 0; if (x == 3) x++; else x += 2; printf("x = %d", x); return 0; } 12
  • 13.
    Revision Questions Q 8#include<stdio.h> int main() { int a = 5; switch(a) { default: a = 4; case 6: a--; case 5: a = a+1; case 1: a = a-1; } printf("%d n", a); return 0; } 13
  • 14.
    Revision Questions Q9 Whatis the output of C Program.? int main() { while(true) { printf("RABBIT"); break; } return 0; } 14
  • 15.
    Revision Questions Q10 Whatis the output of C Program.? int main() { int a=5; while(a==5) { printf("RABBIT"); break; } return 0; } 15
  • 16.
    Determine output: main() { int i= abc(10); printf("%d", --i); } int abc(int i) { return(i++); } 16
  • 17.
    What will beprinted when this program is executed? int f(int x) { if(x <= 4) return x; return f(--x); } void main() { printf("%d ", f(7)); } 17
  • 18.
    Revision Questions Q11 Whatis the output of C Program.? int main() { int a=5; while(a=123) { printf("RABBITn"); break; } printf("GREEN"); return 0; } 18
  • 19.
    Revision Questions Q 12What is the output of C Program.? int main() { int a=5; while(a >= 3); { printf(“TEDDYn"); break; } printf(“BEAR"); return 0; } 19
  • 20.
    Revision Questions Q14 Whatis the output of C Program.? int main() { int k; for(printf(“Hello "); printf(“CSE "); printf(“STUDENTS ")) { break; } return 0; } 20
  • 21.
    Revision Questions Q15 Whatwill be the output of the following code? #include <stdio.h> int main() { int i = 0, j = 0; while (i<5,j<10) { i++; j++; } printf("%d %d", i, j); } 21
  • 22.
    Revision Questions Q16 Whatwill be the output of the following code? int main() { int a = 0; while(a++) { printf(“C programming"); } return 0; } 22
  • 23.
    Revision Questions Q17 Whatwill be the output of the following code? int main() { while(1); { printf("C Programming"); } return 0; } 23
  • 24.
    Revision Questions Q18 Whatwill be the output of the following code? int main() { int i,j,count; count=0; for(i=0; i<5; i++); { for(j=0;j<5;j++); { count++; } } printf("%d",count); return 0; } 24
  • 25.
    Revision Questions Q19 Whatwill be the output of the following code? int main() { int i,j,k,count; count=0; for(i=0;i<5;i++) { for(j=0;j<5;j++) { count++; } } printf("%d",count); return 0; } 25
  • 26.
    Revision Questions Q20 Whatwill be the output of the following code? int main() { int i,j; for(i = 0,j=0;i<5;i++) { printf("%d%d--",i,j); } return 0; } 26
  • 27.
    Revision Questions Q 21What will be the output of following program ? #include <stdio.h> void main() { char cnt=0; for(;cnt++;printf("%d",cnt)) ; printf("%d",cnt); } 27
  • 28.
    Revision Questions Q 24What will be the output of following program ? #include <stdio.h> void main() { int tally; for(tally=0;tally<10;++tally) { printf("#"); if(tally>6) continue; printf("%d",tally); } } 28
  • 29.
    Revision Questions Q 25What will be the output of following program ? #include <stdio.h> void main() { int cnt=1; do { printf("%d,",cnt); cnt+=1; }while(cnt>=10); printf("nAfter loop cnt=%d",cnt); printf("n"); } 29
  • 30.
    Revision Questions Q 27What will be the output of following program ? int main() { int a = 0; while(a++); { printf("Cpp"); } return 0; } 30
  • 31.
    Revision Questions Q 28What will be the output of following program int main() { int i; for(i = 0,i<5,i++) { printf("Hello"); } return 0; } 31
  • 32.
    Revision Questions Q 29What will be the output of following program ? #include <stdio.h> void main() { int k = 0; for (k) printf("Hello"); } 32
  • 33.
    Revision Questions Q 30What will be the output of following program ? #include <stdio.h> int main() { int i = 0; for (; ; ;) printf("In for loopn"); printf("After loopn"); } 33
  • 34.
    Revision Questions Q 31What is output of below program? int main() { for(; ;); for(; ;); printf("Hello"); return 0; } 34
  • 35.
    What is anArray in C language.? A) A group of elements of the same data type. B) An array contains more than one element C) Array elements are stored in memory in continuous or contiguous locations. D) All the above. 35
  • 36.
    An array indexstarts with value A) 0 B) -1 C) 1 D) 2 36
  • 37.
    int main() { int a[]; a[4] = {1,2,3,4}; printf("%d", a[0]); } a) 1 b) 2 c) 3 d) Compiler Error 37
  • 38.
    If the twostrings are identical, then strcmp() function returns A. -1 B. 1 C. 0 D. None 38
  • 39.
    Base address ofan array represents the a) Address of last element of an array b) Address of second element of an array c) Address of first element of an array d) Number of elements 39
  • 40.
    Array elements arealways stored in ________ memory locations.? a) Sequential b) Random c) Sequential and Random d) None of the above 40
  • 41.
    What is theoutput of this program? void main() { int a[8] = {1,2,3,4,5}; printf("%d", a[5]); } A. 5 B. 6 C. 0 D. Garbage Value 41
  • 42.
    #include <stdio.h> int main() { chars1[] = "Hello"; char s2[] = "Hello"; if(s1 == s2) printf("Same"); else printf("Not Same"); return 0; } • A. Not Same • B. Same • C. Compilation Error • D. None of the above 42
  • 43.
    What is theoutput of this program? #include<stdio.h> 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; } 43
  • 44.
    What will bethe output of the program ? #include<stdio.h> #include<string.h> int main() { char str1[20] = "Hello", str2[20] = " World"; printf("%sn", strcpy(str2, strcat(str1, str2))); return 0; } 44
  • 45.
  • 46.
  • 47.
    What will bethe output of the following code? void main() { int a[10]; printf("%d %d", a[-1], a[12]); } 47
  • 48.
    Which of thefollowing correctly accesses the seventh element stored in arr, an array with 100 elements? A. arr[6] B. arr[7] C. arr{6} D. arr{7} E. None of these 48
  • 49.
    • Which ofthe following function is more appropriate for reading in a multi-word string? A. scanf() B. printf() C. gets() D. puts() 49
  • 50.
    REVISION Questions Predict outputof following program int main() { int i; int arr[5] = {5}; for (i = 0; i < 5; i++) printf("%d ", arr[i]); return 0; } 50
  • 51.
    REVISION Questions Q7 Whatis the output int main() { int bus[3][] = {6,5,4,3,2,1}; printf("%d %d", bus[0][0], bus[2][1]); return 0; } 51
  • 52.
    REVISION Questions Q9 findthe output int main() { char str1[]=“CU"; char str2[20]; str2= str1; printf("%s",str2); return 0; } 52
  • 53.
    REVISION Questions Q10 Whatis the output? int main() { char str[25]; scanf("%s", str); printf("%s",str); return 0; } //input: New Delhi 53
  • 54.
    #include<stdio.h> int add(int a,intb=12) { return a+b; } int main() { int c ; c=add(1,2); printf("%d",c); } 54
  • 55.
    #include<stdio.h> int add(int a,intb) { return a,return b; } int main() { int c ; c=add(1,2); printf("%d",c); } 55
  • 56.
    #include<stdio.h> int add(int a,intb) { return a,b; } int main() { int c ; c=add(1,2); printf("%d",c); return 0; } 56
  • 57.
    REVISION Questions Find theoutput void main() { int a; printf("COUNT="); a=show(); printf("%d", a); } int show() { return 15; return 35; } 57
  • 58.
    Rohan writes thecode for a function that computes the sum of n natural numbers of the inputted number n. int sum_n(int n) { if(n==1) return 1; else missing statement } Fill in the missing statement. 58
  • 59.
    • Sam iswriting a code which has a function which calls itself. Which programming concept is Sam using? • The values passed to a function at the time of function calling are knows as______________ • If we have to write a program to print first n natural ,which loop is ideal? 59
  • 60.
    Predict the Outputof following C program ,if line 2 will be removed? #include<stdio.h> int add(int,int);//line 2 int add(int a,int b) { int sum=a+b; return sum; } int main() { printf("%d",add(1,2)); return 0; } 60
  • 61.
    REVISION Questions Q2 Findthe output int main() { int a[][] = {{1,2},{3,4}}; int i, j; for (i = 0; i < 2; i++) for (j = 0; j < 2; j++) printf("%d ", a[i][j]); return 0; } 61
  • 62.
    REVISION Questions Q4 Whatis the output ? int main() { char marks={'A','B','C'}; printf("%c", marks[0]); } 62
  • 63.
    REVISION Questions Q16 Whatis the output? 63
  • 64.
    21#include<stdio.h> int main() { char str[7]= "IndiaRock"; printf("%sn", str); return 0; } 64
  • 65.
    Revision Questions Q 23What will be the output of following program ? #include < stdio.h > int main() { int tally=0; for(;;) { if(tally==10) break; printf("%d ",++tally); } return 0; } 65
  • 66.
    What is theoutput of C Program.? int main() { int k, j; for(k=1, j=10; k <= 5; k++) { printf("%d ", (k+j)); } return 0; } 66
  • 67.
    find the output #include<stdio.h> intmain() { int i = -5; while (i <= 5) { if (i >= 0) break; else { i++; continue; } printf(“ C PROGRAMMING"); } return 0; } 67
  • 68.
    Revision Questions Q 22What will be the output of following program ? #include <stdio.h> void main() { int i=1; while (i<=5) { printf("%d",i); if (i==5) goto print; i++; } } fun() { print: printf("includehelp.com"); } 68
  • 69.
    What is theoutput of C Program.? int main() { int a=32; do { printf("%d ", a); a++; if(a > 35) break; }while(1); return 0; } 69
  • 70.
    void main() { printf(5+"Good Morningn"); } A.Good Morning B. M C. Good D. Morning E. None of these 70
  • 71.
    Let x bean array. Which of the following operations is/are illegal? a) ++x b) x+1 c) x++ d) x*2 71
  • 72.
    What is theoutput of this program? #include <stdio.h> int main() { int arr[5] = {1,2,3,4,5}; int p, q, r; p = ++arr[1]; q = arr[1]++; r = arr[p++]; printf("%d, %d, %d", p, q, r); return 0; } 72
  • 73.
    Guess the output. #include<stdio.h> intmain() { int a[8] = {1,2,[4]=7,8,9}; for(int i=0;i<8;i++) printf("%d ",a[i]); } 73
  • 74.
    # include <stdio.h> intmain() { char str1[] = “Chandigarh"; char str2[] = {‘c’,’h’,’a’,’n’,’d’,’I’,’g’,’a’,’r’,’h’}; int n1 = sizeof(str1)/sizeof(str1[0]); int n2 = sizeof(str2)/sizeof(str2[0]); printf("n1 = %d, n2 = %d", n1, n2); return 0; } 74
  • 75.
    • Which loopis faster in C Language, for, while or Do While.? • a) for • b) while • c) do while • d) All work at same speed 75
  • 76.
    Revision Questions Q 26What will be the output in given input? • When, input: 'a' and 1 int main() { int n,i=0; while(scanf("%d",&n)==1) { printf("ENDn"); } return 0; } 76

Editor's Notes

  • #7 Infinite loop
  • #8 Cu AU
  • #9 INFINITE LOOP
  • #10 C PROGRAMMING 5 times
  • #11 Nothing gets printed
  • #12 99 99 99
  • #13 X=2
  • #14 5
  • #15 COMPILE TIME ERROR
  • #16 RABBIT
  • #19 RABBIT GREEN
  • #20 INFINITE LOOP WITH NO ANSWER
  • #21 HELLO CSE
  • #22 10 10
  • #23 Nothing will be printed
  • #24 Infinite loop
  • #25 1
  • #26 25
  • #27 00—10—20—30—40--
  • #28 1 Before entering into the for loop the CHECK CONDITION is "evaluated". Here it evaluates to 0 (false) and comes out of the loop, and i is incremented (note the semicolon after the for loop).
  • #29 #0#1#2#3#4#5#6###
  • #30 1, After loop cnt=2 do while is an exit controlled loop, here loop body executed first, then condition will be checked.
  • #31 Cpp
  • #32 for loop should have semicolumn ; not comma , in its syntax. Using , instead of ; produces compilation error.
  • #34 error
  • #35 Hint: blank for loop with ; ; is always infinite loop. printf() will never executed in this program.
  • #43 Explanation: The base address of s1 and s2 are checked which are not equal and hence the else part will execute.
  • #44 A. 3, 2, 15 Explanation:- >> int a[5] = {5, 1, 15, 20, 25}; The variable arr is declared as an integer array with a size of 5 and it is initialized to a[0] = 5, a[1] = 1, a[2] = 15, a[3] = 20, a[4] = 25. >> int i, j, m; The variable i, j, m are declared as an integer type. >> i = ++a[1]; becomes i = ++1; Hence i = 2 and a[1] = 2 >> j = a[1]++; becomes j = 2++; Hence j = 2 and a[1] = 3. >> m = a[i++]; becomes m = a[2]; Hence m = 15 and i is incremented by 1(i++ means 2++ so i=3) >> printf(“%d, %d, %d”, i, j, m); It prints the value of the variables i, j, m Hence the output of the program is 3, 2, 15.
  • #45 Hello World
  • #51 5 0 0 0 0
  • #52 ary[3][] has missing column count. Column count is a must for any multidimensional array.
  • #53 Direct assignment not possible error
  • #54 New
  • #55 error
  • #57 2
  • #58 15
  • #62 error
  • #63 Compile time error
  • #64 10
  • #65 Here str[] has declared as 7 character array and into a 8 character is stored. This will result in overwriting of the byte beyond 7 byte reserved for '\0'.
  • #66 1 2 3 4 5 6 7 8 9 10 for(; ;) it is possible in c, there is no need to place condition with in the for(), you can place condition with in the body of the loop.
  • #67  11 12 13 14 15
  • #69 compiler error: Undefined label ‘print’ in function main. Labels have functions scope, in other words the scope of the labels is limited to functions. The label ‘print’ is available in function fun() Hence it is not visible in function main.
  • #70  32 33 34 35
  • #73 C. 4 3 4
  • #74  1 2 0 0 7 8 9 0
  • #77 No output and END scanf function return integer value i.e. 1 if successful read data otherwise 0 in unsuccessfully read data. 1_ For, input ‘a’, scanf return 0 and while will not execute. 2_ For, input 1, scanf return 1 and while will be execute.