Skip to content

Objective C Interview Questions

Reading Time: 4 minutes

Objective C is a general purpose, object oriented programming language. It is mainly used by Apple for the OS X and iOS operating systems. Here are the top 25 Objective C interview questions and answers.

1. Explain what objective-C program basically consists of ?

It basically consist of

  • Preprocessor commands
  • Interface
  • Statements & Expressions
  • Comments
  • Implementation
  • Method
  • Variables

2. Define #Import ?

# import is  a preprocessor construct to avoid multiple inclusion of the same file.

#import ;Object.h;
is an alternative to
#include ;Object.h;
where the .h file is protected itself against multiple inclusions :
#ifndef _OBJECT_H_

…
#define _OBJECT_H_
#endif

3. What is Objective C ?

It is a type of programming language which helps in the process of Object Oriented Programming. ObjectiveC is used by Apple for OS X and iOS operating system.

4. What is a protocol ?

It is a language feature in objective C which provides multiple inheritance in a single inheritance language . There are two types of protocol supported by objective C

  • Ad hoc protocols called informal protocol
  • Compiler protocols called formal protocols

5. List the  methods used in NSURL connection in Objective C ?

  • Connection did receive data
  • Connection fail with error
  • Connection did receive response
  • Connection did finish loading

6. List the methods in  Objective C  for memory management?

Two methods are used for memory management in Objective C

  • MRR- Manual Retain Release
  • ARC- Automatic Reference Counting

7. Write the output of the below code ?

#include
#define var 3
int main(){
char *cricket[var+~0]={"julies","kailas"};
char *ptr=Cycling[1+~0];
printf("%c",*++ptr);
return 0;
}
Output

1

Explanation

var +~0 = 3 + ~0 = 3 + (-1) = 2

Assume string “julies” and “kailas” has stored at

memory address 100 and 500 respectively

See also  Top 25+ Important Big Data Interview Questions

For string “julies”: 100 to 106

For string “kailas”: 500 to 506

In this program Cycling is array of character‟s pointer

of size 2. So array Cycling  will keep the memory

address of first character of both strings i.e. content

of array Cycling is:

Cycling[2] = {100,500}

ptr is character pointer which is pointing to the fist

element of array cricket. So, ptr = 100

Now consider on *++ptr

ptr = 100, after ++ptr, ptr = 101

*(++ptr) = *(101) = content of memory address 101.

character is l.

8. Write the output of the below code ?

#include

int main(){

int const SIZE=5;

int expr;

double value[SIZE]={2.0,4.0,6.0,8.0,10.0};

expr=1|2|3|4;

printf("%f",value[expr]);

return 0;

}
Output

Compilation error

Explanation

In C Size of any array cannot be constant variable.

9. Write the output of the below code ?

#include

int main(){

long int 1b=85;

printf("%ld",1b);

return 0;

}
Output

Compilation error

Explanation

Compilation error because the name of the variable is invalid. Variable name should start with alphabet or underscore.

10. Write the output of the below code ?

#include

int main(){

int i=2;

i=3+3*i++;

printf("%d",i);

return 0;

}
Output

8

Explanation

when i++  postfix increment operator is used in  expression, it first assign  its value in the expression  and then  it increments the value of variable by two . So,

i = 3 +3  *2

i=6

i will be incremented by 2

i=6+2=8

objective c interview questions

11. Write the output of the below code ?

#include

int main(){

int a=5,b=10,c=1;

if(a&&b>c){

printf("8subjects");

}
else{
break;
}
return 0;
}
Output

Compilation Error

Explanation

Break keyword is not a part of if -else statement. It can be used in case of loop or case statements. So the compiler shows the misplaced break error.

12. Write the output of the below code ?

#include

int main(){

int chk=2;

switch(chk){

case 1: printf("Sachin");

case 2: printf(" Dhoni");

case 3: printf(" Virat");

default: printf(" Zaheer ");

}

return 0;

}
Output

Dhoni Virat Zaheer.

Explanation

See also  ASP.NET Interview Questions

The program control will come in each case after the case condition is satisfied.

13. Write a program to print Hello World without using any semicolon ?

void main(){

if(printf("Hello world")){

}

}
Output

Hello World

14. List the characteristics of Objective C ?

  • The class is defined as @inheritance and @implementation
  • Objects have instance variables
  • Objects and instance variables have scope.
  • Objects are referred as receivers, as it receives message .

15. What is an accessor method ?

It is a method belonging to  a class that enables you to get and set the values of instance valuable contained within the class.

16. Define single inheritance in Objective C ?

In Objective C subclass can only be obtained from a single direct parent class this concept is called “single inheritance”.

17.  Define Polymorphism in Objective C ?

It is referred to a capability of base class pointer to call the function.

18. what is synthesized in Objective-C ?

In Objective C  Once you have declared the property,then you have to tell the compiler instantly by using synthesize directive ,Which helps the  compiler to generate a getter &setter message.

19. How is string represented in Objective C ?

String is represented by using NSS string and its sub-class.   NSMutableString provides several ways for creating string objects.

20. How to call the function in Objective C ?

We can call the function by Account -> Object Name -> Display account information ->  Method name.

21. Explain Data encapsulation in  Objective C ?

It is referred to the mechanism of connecting the data and the functions that use them.

22. what are the classes used for to establish a connection between application to the web server ?

  • NSURL
  • NSURL REQUEST
  • NSURL CONNECTION
See also  Help Desk Interview Questions and Answers

23. Explain what is the  use of category in Objective-C ?

It is used to extend an existing class by appending behavior that is useful only in  certain situations. Extensions and categorizes are used to add such extension to existing classes, Syntax to define a category is @interface keyword.

24. Explain whether NS object is a parent class or derived class ?

It is a parent class and consist of number of instance variable and instance methods.

25. Define how the class IMPLEMENTATION is represented in Objective C ?

IMPLEMENTATION is represented with @implementation directive and ends with @end.

 

 

 

 

Leave a Reply