# Objective-c Coding Test

Approved & Edited by ProProfs Editorial Team
At ProProfs Quizzes, our dedicated in-house team of experts takes pride in their work. With a sharp eye for detail, they meticulously review each quiz. This ensures that every quiz, taken by over 100 million users, meets our standards of accuracy, clarity, and engagement.
| Written by Jaksiboy
J
Jaksiboy
Community Contributor
Quizzes Created: 924 | Total Attempts: 12,123,294
Questions: 10 | Attempts: 920  Settings  Objective-C is a general-purpose, object-oriented programming language derived from the C programming language. It was the main programming language used by Apple for their OS X and iOS operating systems prior to the introduction of SWIFT. After all that history, I am sure you will want to know more about this programming language. Find out how much you know by attempting this quiz.

• 1.

### What is the value of z after executing this sequence (check indentation)? int x = 100, y = 50, z = -1; if ( x + y > 50)    if ( x + y < 100)       z = 0; else    z = 1;

• A.

-1

• B.

0

• C.

1

• D.

This problem is too hard!

C. 1
Explanation
The value of z is 1 because the first if statement evaluates to true since 100 + 50 is greater than 50. Then, the nested if statement also evaluates to true since 100 + 50 is less than 100. Therefore, z is assigned a value of 0.

Rate this question:

• 2.

### What does the leading + sign at the start of a method indicate?

• A.

An instance method

• B.

A class method

• C.

An initialization method

• D.

None of the above

B. A class method
Explanation
The leading + sign at the start of a method indicates that it is a class method. Class methods are methods that are associated with the class itself rather than with an instance of the class. They can be called on the class directly, without creating an instance of the class.

Rate this question:

• 3.

### What is wrong with this sequence of code? sum = 100; int sum;

• A.

"sum" is a reserved word

• B.

A variable must be declared before it can be used

• C.

Nothing is wrong

• D.

Everything is wrong! I hate Objective-C!

B. A variable must be declared before it can be used
Explanation
In this sequence of code, the variable "sum" is being assigned a value of 100 before it is declared as an integer using the "int" keyword. In programming, variables must be declared before they can be used. Therefore, the correct answer is "A variable must be declared before it can be used."

Rate this question:

• 4.

### Given int a = 10, b = 20, c; b *= a + 5; What is the resulting value of b?

• A.

205

• B.

200

• C.

300

• D.

The statement will generate a compiler error

C. 300
Explanation
The resulting value of b is 300. The expression "b *= a + 5" is equivalent to "b = b * (a + 5)". Since a is 10, the expression becomes "b = b * (10 + 5)". Since b is initially 20, the expression further simplifies to "b = 20 * 15", which evaluates to b = 300.

Rate this question:

• 5.

### What is the file extension name used for Objective-C code?

• A.

.c

• B.

.pl

• C.

.m

• D.

.cpp

C. .m
Explanation
The file extension name used for Objective-C code is .m. This extension is commonly used in Objective-C programming to indicate that the file contains code written in the Objective-C language. Other file extensions mentioned in the options, such as .cpp, .pl, and .c, are used for different programming languages like C++, Perl, and C. Therefore, .m is the correct answer for the file extension name used for Objective-C code.

Rate this question:

• 6.

### What is the value of s after executing this loop: int i = 0, s = 0; while (i < 5)    s += ++i;

• A.

16

• B.

15

• C.

14

• D.

11

B. 15
Explanation
The value of 's' is 15 after executing the loop because the loop iterates 5 times. In each iteration, 'i' is incremented by 1 using the pre-increment operator (++i), and then added to 's'. So, in the first iteration, 'i' becomes 1 and 's' becomes 1. In the second iteration, 'i' becomes 2 and 's' becomes 3. This process continues until the fifth iteration, where 'i' becomes 5 and 's' becomes 15.

Rate this question:

• 7.

### Which value is not equivalent to the others?

• A.

0x64

• B.

0144

• C.

100

• D.

0XE5

D. 0XE5
Explanation
The value 0xE5 is not equivalent to the others because it is represented in hexadecimal notation, while the other values are represented in decimal or octal notation.

Rate this question:

• 8.

### Which is an example of an invalid variable name?

• A.

Floats

• B.

X123\$

• C.

Two_By_Four

• D.

_Rectangle

B. X123\$
Explanation
The variable name "x123\$" is an example of an invalid variable name because it starts with a special character (\$) which is not allowed in variable names. In most programming languages, variable names can only start with a letter or an underscore, not with a special character.

Rate this question:

• 9.

### What is a local variable that has no default initial value and does not retain its value through method calls?

• A.

A static variable

• B.

An auto variable

• C.

A global variable

• D.

None of the above

B. An auto variable
Explanation
An auto variable is a local variable that has no default initial value and does not retain its value through method calls. Unlike global and static variables, which have default initial values and can retain their values across method calls, an auto variable is only accessible within the scope of the method in which it is declared and must be explicitly assigned a value before it can be used. Therefore, the correct answer is an auto variable.

Rate this question:

• 10.

### What should you do If you want to return an object back to the caller of your method and you want to mark the object for a later release?

• A.

Autorelease it before returning

• B.

Copy it before returning

• C.

Release it before returning

• D.

Retain it before returning Back to top