# Objective-c Coding Test

Approved & Edited by ProProfs Editorial Team
The editorial team at ProProfs Quizzes consists of a select group of subject experts, trivia writers, and quiz masters who have authored over 10,000 quizzes taken by more than 100 million users. This team includes our in-house seasoned quiz moderators and subject matter experts. Our editorial experts, spread across the world, are rigorously trained using our comprehensive guidelines to ensure that you receive the highest quality quizzes.
| By Jaksiboy
J
Jaksiboy
Community Contributor
Quizzes Created: 832 | Total Attempts: 12,162,621
Questions: 10 | Attempts: 943

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

A. Autorelease it before returning
Explanation
If you want to return an object back to the caller of your method and mark it for a later release, you should autorelease it before returning. Autoreleasing an object means that it will be automatically released at a later time, allowing the caller to use the object without worrying about memory management. This is useful when you want to pass ownership of the object to the caller, but still want to ensure that it will be released when it is no longer needed.

Rate this question:

Quiz Review Timeline +

Our quizzes are rigorously reviewed, monitored and continuously updated by our expert board to maintain accuracy, relevance, and timeliness.

• Current Version
• Mar 21, 2023
Quiz Edited by
ProProfs Editorial Team
• Dec 14, 2017
Quiz Created by
Jaksiboy

Related Topics