[go: up one dir, main page]

0% found this document useful (0 votes)
79 views15 pages

ICS - 103 - Practice Questions

This document contains practice questions for an ICS 103 computer programming course in C language. It includes 6 multiple choice questions testing concepts like if/else conditions, functions, switch statements, and basic C syntax.

Uploaded by

Non Non
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
79 views15 pages

ICS - 103 - Practice Questions

This document contains practice questions for an ICS 103 computer programming course in C language. It includes 6 multiple choice questions testing concepts like if/else conditions, functions, switch statements, and basic C syntax.

Uploaded by

Non Non
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 15

‫اململكـــــــــة العربــيـــــة السعوديـــــة‬ Kingdom of Saudi Arabia

‫وزارة التعـــــليــــــــــــــــــــــــــــــــــــــــــــــــــم‬ Ministry of Education


‫جـــامعـــــــــــة حائـــــــــــــــــــــــل‬ University of Hail
‫كليــــــــــــــة علـــــــــــــــــوم وهــنــــــــــــــدســــــــــة‬ College of Computer Science and Engineering
‫الحــــــــاســـــــــــــــب اآللـي‬
‫قســـــــــــــــم علــــــــــــــــــوم‬ Department of Computer Science and Software Engineering
‫الحــــــــاســـــــــــــــب وهــنــــــــــــــدســــــــــة الــبرمجيــــــــــــــــــــــــــــــــــــــــات‬

Computer Programming in C– ics 103

Practice Questions
Prepared by: Mrs. Sabiha begum

1. Choose the correct answer for each question below:

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

1 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
‫الحــــــــاســـــــــــــــب وهــنــــــــــــــدســــــــــة الــبرمجيــــــــــــــــــــــــــــــــــــــــات‬

4. Given the following funcGon


int strange(int x, int y)
{
If(x > y)
return x + y;
else
return x – y;
}
What is the output of the following statement?
prin@( “%d” , strange(4, 5));
a) 2
b) 1
c) -1
5. What is the output of the following code?
int number = 8;
if (number < 8)
prin@(“%d”, 1);
else
prin@(“%d”, 2);
a) 1
b) 2
c) 8
6. What is y a5er the following switch statement is executed?
int x = 3; int y = 4;
2 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‬‬
‫الحــــــــاســـــــــــــــب وهــنــــــــــــــدســــــــــة الــبرمجيــــــــــــــــــــــــــــــــــــــــات‬

‫)‪switch (x + 3‬‬
‫{‬
‫;‪case 6: y = 0‬‬
‫;‪case 7: y = 1‬‬
‫;‪default: y += 1‬‬
‫}‬
‫‪a) 2‬‬
‫‪b) 3‬‬
‫‪c) 4‬‬

‫‪3‬‬ ‫‪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
‫الحــــــــاســـــــــــــــب وهــنــــــــــــــدســــــــــة الــبرمجيــــــــــــــــــــــــــــــــــــــــات‬

7. Which of the following is a logical NOT operator?


A-!
B - &&
C-&
D - All of the above

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. }

a) Compile time error


b) -1
c) 1
d) Implementation defined
View Answer
4 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
‫الحــــــــاســـــــــــــــب وهــنــــــــــــــدســــــــــة الــبرمجيــــــــــــــــــــــــــــــــــــــــات‬

Answer: b

. What will be the final value of x in the following C code?

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

. What is the precedence of arithmetic operators (from highest to lowest)?


a) %, *, /, +, –
b) %, +, /, *, –
c) +, -, %, *, /
d) %, +, -, *, /
View Answer

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) +, -, %

5 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
‫الحــــــــاســـــــــــــــب وهــنــــــــــــــدســــــــــة الــبرمجيــــــــــــــــــــــــــــــــــــــــات‬

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

6 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
‫الحــــــــاســـــــــــــــب وهــنــــــــــــــدســــــــــة الــبرمجيــــــــــــــــــــــــــــــــــــــــات‬

d) error
View Answer

Answer: a

How many times i value is checked in the following C code?

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++)

7 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
‫الحــــــــاســـــــــــــــب وهــنــــــــــــــدســــــــــة الــبرمجيــــــــــــــــــــــــــــــــــــــــات‬

6. printf("Hello");
7. }

a) Run time error


b) Hello is printed thrice
c) Hello is printed twice
d) Hello is printed infinitely
View Answer

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;

8 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
‫الحــــــــاســـــــــــــــب وهــنــــــــــــــدســــــــــة الــبرمجيــــــــــــــــــــــــــــــــــــــــات‬

int array[size] = {1, 2, 3};


d) All of the mentioned
View Answer

Answer: c

18. The placeholder %s is used in the format of


a. char
b. string
c. int
d. float
Answer: b
. What will be the output of the program ?
#include <stdio.h>
int main () {
char greeting[6] = {'H', 'e', 'l', 'l', 'o', '\0'};
printf("Greeting message: %s\n", greeting );
return 0;
}
a. Hello
b. “Hello”
c. ‘Hello
d. H,e,l,I,o

Answer: a

2. What is the output of the following code?

Answer:
voidmaxValue(int value1, int value2)
2
{
if (value1 > value2)
printf(“%d”, value1);

9 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
‫الحــــــــاســـــــــــــــب وهــنــــــــــــــدســــــــــة الــبرمجيــــــــــــــــــــــــــــــــــــــــات‬

else
printf(“%d”, value2);
}
int main() {
int max = 0;
maxValue(1, 2);
return 0;
}

3. What is the output of the following code?


for(i=1; i < 5; i++) Answer:
printf(“%d\n”, 2*i);
2
4
6

4. What is the output of the following code?


int k;
Answer:
for(k = 1; k <= 4; k++) {
printf (“A”); AAAA B

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");

10 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
‫الحــــــــاســـــــــــــــب وهــنــــــــــــــدســــــــــة الــبرمجيــــــــــــــــــــــــــــــــــــــــات‬

else
printf("Good Morning!\n");

6. What is the output of the following code?


int n = 12%5;
Answer:
if (n/2 == 1)
printf( "Two\n"); Two
That was fun!
printf("That was fun!\n");
7. What is the output of the following code?
int n = 12%5;
Answer:
if (n == 1)
printf( "Two\n"); That was fun!
printf("That was fun!\n");
8. What is the output of the following code?
int n = 12%5;
Answer:
if (n == 1)
printf( "Two\n"); That was fun!
else
printf("That was fun!\n");

11 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
‫الحــــــــاســـــــــــــــب وهــنــــــــــــــدســــــــــة الــبرمجيــــــــــــــــــــــــــــــــــــــــات‬

9. What is the output of the following code?


int m=2:
Answer:
switch (m)
Good Afternoon
{ case 1 : printf(“Good Morning”); break;
Good Evening
case 2 : printf(“Good Afternoon”);
case 3 : printf(“Good Evening”); break;
default: printf(“Error”); }
10.What is the output of the following code?
int i;
Answer:
int j= 9;
1 9
for (i= 1; i < 12; i+=3 )
4 9
{ printf(“%d %d \n”, i , j);
7 9

}
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 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
‫الحــــــــاســـــــــــــــب وهــنــــــــــــــدســــــــــة الــبرمجيــــــــــــــــــــــــــــــــــــــــات‬

String Functions Description

strstr( ) Returns pointer to first occurrence of str2 in str1

strrstr( ) Returns pointer to last occurrence of str2 in str1

strdup( ) Duplicates the string

strlwr( ) Converts string to lowercase

strupr( ) Converts string to uppercase

strrev( ) Reverses the given string

strset( ) Sets all character in a string to given character

strnset( ) It sets the portion of characters in a string to given character

strtok( ) Tokenizing given string using delimiter

String Functions Description

strstr( ) Returns pointer to first occurrence of str2 in str1

strrstr( ) Returns pointer to last occurrence of str2 in str1

strdup( ) Duplicates the string

13 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
‫الحــــــــاســـــــــــــــب وهــنــــــــــــــدســــــــــة الــبرمجيــــــــــــــــــــــــــــــــــــــــات‬

strlwr( ) Converts string to lowercase

strupr( ) Converts string to uppercase

strrev( ) Reverses the given string

strset( ) Sets all character in a string to given character

strnset( ) It sets the portion of characters in a string to given character

strtok( ) Tokenizing given string using delimiter

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‬‬
‫}‬

‫‪13.Find out the square root and power‬‬

‫‪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‬‬

‫‪15‬‬ ‫‪ICS – 103 Practice Questions‬‬


‫‪Prepared by: Mrs. Salam Albazrawi‬‬

You might also like