ICS - 103 - Practice Questions
ICS - 103 - Practice Questions
Practice Questions
Prepared by: Mrs. Sabiha begum
1. If y has the value 5 what will be the value of the variable y a5er the following piece of C
is executed?
if (y > 0)
y = y + 2;
a) 7
b) 5
c) 2
2. If p has the value 3 and max has the value 5, what will be the value of the variable max
a5er the following piece of C++ is executed?
if (p < max)
max = p
a) 3
b) 5
c) 6
3. Which of the following is selecGon statement in C ?
a) while
b) for
c) switch
)switch (x + 3
{
;case 6: y = 0
;case 7: y = 1
;default: y += 1
}
a) 2
b) 3
c) 4
Answer : A
8. Which of the following variable cannot be used by switch-case statement?
A - char
B - int
C - float
D - Double
Answer : C
9. Which statement can print \n on the screen?
A - printf("\\n");
B - printf("n\");
C - printf("n");
D - printf('\n');
Answer : A
1. What will be the output of the following C code?
1. #include <stdio.h>
2. int main()
3. {
4. int i = -3;
5. int k = i % 2;
6. printf("%d\n", k);
7. }
Answer: b
1. #include <stdio.h>
2. void main()
3. {
4. int x = 5 * 9 / 3 + 9;
5. }
a) 3.75
b) Depends on compiler
c) 24
d) 3
Answer: c
Answer: a
Which of the following is not an arithmetic operation?
a) a * = 10;
b) a / = 10;
c) a ! = 10;
d) a % = 10;
View Answer
Answer: c
Which among the following are the fundamental arithmetic operators, i.e, performing the desired operation can be
done using that operator only?
a) +, –
b) +, -, %
c) +, -, *, /
d) +, -, *, /, %
View Answer
Answer: a
What is the result of logical or relational expression in C?
a) True or False
b) 0 or 1
c) 0 if an expression is false and any positive number if an expression is true
d) None of the mentioned
View Answer
Answer: b
Which among the following is NOT a logical or relational operator?
a) !=
b) ==
c) ||
d) =
View Answer
Answer: d
What will be the output of the following C code?
1. #include <stdio.h>
2. void main()
3. {
4. int x = 5;
5. if (x < 1)
6. printf("hello");
7. if (x == 5)
8. printf("hi");
9. else
10. printf("no");
11. }
a) hi
b) hello
c) no
d) error
View Answer
Answer: a
1. #include <stdio.h>
2. int main()
3. {
4. int i = 0;
5. do {
6. i++;
7. printf("in while loop\n");
8. } while (i < 3);
9. }
a) 2
b) 3
c) 4
d) 1
View Answer
Answer: b
5. Which datatype can accept the switch statement?
a) int
b) char
c) long
d) all of the mentioned
View Answer
Answer: d
What will be the output of the following C code?
1. #include <stdio.h>
2. void main()
3. {
4. double k = 0;
5. for (k = 0.0; k < 3.0; k++)
6. printf("Hello");
7. }
Answer: b
Which of the following is a correct format for declaration of function?
a) return-type function-name(argument type);
b) return-type function-name(argument type){}
c) return-type (argument type)function-name;
d) all of the mentioned
View Answer
Answer: a
the value obtained in the function is given back to main by using ________ keyword.
a) return
b) static
c) new
d) volatile
View Answer
Answer: a
5. Which of the following declaration is illegal?
a)
int a = 0, b = 1, c = 2;
int array[3] = {a, b, c};
b)
int size = 3;
int array[size];
c)
int size = 3;
Answer: c
Answer: a
Answer:
voidmaxValue(int value1, int value2)
2
{
if (value1 > value2)
printf(“%d”, value1);
else
printf(“%d”, value2);
}
int main() {
int max = 0;
maxValue(1, 2);
return 0;
}
printf (“B”);
}
5. What is the output of the following code?
int m=20:
Answer:
if (m >= 12)
Good after noon!
printf("Good after noon!\n");
else
printf("Good Morning!\n");
}
11.Write an if / else statement that will print the largest of two variables A or B .
int A , B ;
if(A>B)printf(“%d”,A);
else
printf(“%d”,B);
12.Write a program that shows a message "PASS" if value entered by user greater than or
equal 60 and print "Fail" otherwise.
#include<stdio.h>
int main()
{
int value;
printf("Enter a value: ");
scanf("%d", &value);
if (value>=60)
printf("Pass\n");
else
printf("Fail\n");
14 ICS – 103 Practice Questions
Prepared by: Mrs. Salam Albazrawi
اململكـــــــــة العربــيـــــة السعوديـــــة Kingdom of Saudi Arabia
وزارة التعـــــليــــــــــــــــــــــــــــــــــــــــــــــــــم Ministry of Education
جـــامعـــــــــــة حائـــــــــــــــــــــــل University of Hail
كليــــــــــــــة علـــــــــــــــــوم وهــنــــــــــــــدســــــــــة College of Computer Science and Engineering
الحــــــــاســـــــــــــــب اآللـي
قســـــــــــــــم علــــــــــــــــــوم Department of Computer Science and Software Engineering
الحــــــــاســـــــــــــــب وهــنــــــــــــــدســــــــــة الــبرمجيــــــــــــــــــــــــــــــــــــــــات
;)"system("pause
;return 0
}
1. Sqrt(16)=4
2. Sqrt(4)=2
3. Sqrt(9)=3
4. Sqrt(49)=7
5
___________=)5. sqrt(25
10
____________=)6. sqrt(100
Power(3,2)=32=9
Power(4,2)=42=16
2
5 =25
____________=)Power(5,2
3
6 = 216
_________________=)Power(6,3