Basic Questions for ios developers

Source: Internet
Author: User

Reference: http://www.cnblogs.com/duchengdong/archive/2012/03/30/2425300.html

1,

main()  {     int a[5]={1,2,3,4,5};     int *ptr=(int *)(&a+1);      printf("%d,%d",*(a+1),*(ptr-1)); } 

Answer: 2, 5

Analysis: * (a + 1) is a [1], which is 2; & a + 1 is not the first address + 1. The system will consider adding an array offset of, is the size of an array offset (in this example, It is 5 int)
Int * ptr = (int *) (& a + 1 );
Then ptr is actually & (a [5]), that is, a + 5

2. Use the preprocessing command # define to declare a constant to indicate the number of seconds in a year (ignore the leap year)

#define SECONDS_PER_YEAR (60 * 60 * 24 * 365)UL 

# Define basic syntax knowledge (cannot end with a semicolon or use of parentheses)

Knowing that the pre-processor will calculate the constant expression value for you

Realize that this expression will overflow the integer data of a 16-bit machine. Therefore, use the long integer character L to tell the compiler that this constant is a long integer.

If UL (representing an unsigned integer) is used in the expression)

3. Write a standard macro MIN. The macro inputs two parameters and returns a smaller one.

#define MIN(A,B) ((A) <= (B) ? (A) : (B))  

4. Write an NSString class implementation

+ (id)initWithCString:(const char *)nullTerminatedCString encoding:(NSStringEncoding)encoding; + (id) stringWithCString: (const char*)nullTerminatedCString              encoding: (NSStringEncoding)encoding {   NSString  *obj;   obj = [self allocWithZone: NSDefaultMallocZone()];   obj = [obj initWithCString: nullTerminatedCString encoding: encoding];   return AUTORELEASE(obj); } 

5. Does obj-c have multiple inheritance types? Is there any alternative?

No. Multi-inheritance is implemented using protocol delegation in cocoa.

6. Is there a private Method for obj-c? Is there a variable?

There are only two methods: static method and instance method. The default value is public.

Variables: private, protected, and public. The default value is private.

 

@interface Controller : NSObject { NSString *something; } + (void)thisIsAStaticMethod; - (void)thisIsAnInstanceMethod; @end @interface Controller (private) - (void)thisIsAPrivateMethod; @end

The above method can be used to achieve method privatization.

7. What does the keyword const mean? What about modifier classes? What is static? Used for classes? And the role of extern C

  • Const means read-only

Const int a; a is a constant integer.

Int const a; Same as above, a is a constant integer.

Const int * a; a is the pointer to a constant INTEGER (that is, the integer cannot be modified, but the pointer can be)

Int * const a; a is a constant pointer to the integer (that is, the integer number can be modified, but the pointer cannot be modified)

Int const * a const; a is a constant pointer to a constant integer.

  • Static keyword

(1) The static variable in the function body applies to this function body. Unlike the auto variable, the memory of this variable is allocated only once, therefore, the value remains the value of the previous time during the next call;

(2) The static global variables in the module can be accessed by the functions used in the module, but cannot be accessed by other functions outside the module;

(3) The static function in the module can only be called by other functions in the module. The scope of use of this function is limited to the module that declares it;

(4) static member variables in the class belong to the entire class and only one copy of all objects in the class;

(5) The static member function in the class belongs to the whole class. this function does not receive the this pointer, so it can only be a static member variable of the category.

  • Function of extern "C"

(1) functions or variables limited by extern "C" are of the extern type;

Extern is a keyword in C/C ++ that indicates the range (visibility) of functions and global variables. This keyword tells the compiler,
The declared functions and variables can be used in this module or other modules.

(2) variables and functions modified by extern "C" are compiled and connected in the C language;

  • Extern "C"Usage
(1) reference the functions and variables in C language in C ++. When the header file of C language (for example, cExample. h) is included
Perform the following operations:
Extern "C"
{
# Include "cExample. h"
}
In the header file of the C language, the external function can only be specified as the extern type. The C language does not support the extern "C" declaration,
When the. c file contains extern "C", a compilation syntax error occurs.
(2) When C references functions and variables in C ++, the header file of C ++ needs to add extern "C", but does not
You can directly reference this header file that declares extern "C". You should only declare the extern "C" function defined in C ++
Extern type.

8. Framework Classification

  • Audio and video

Core Audio

OpenAL

Media Library

AVFoundation

  • Data Management

Core Data

SQLite

  • Images and animations

Core Animation

OpenGL ES

Quartz 2D

  • Network

Bonjour

WebKit

BSD Sockets

  • User Application

Address Book

Core Location

Map Kit

Store Kit

9. Advantages and Disadvantages of obj-c

Advantages of obj-c:

1) Cateogies

2) Posting

3) Dynamic Identification

4) indicator calculation

5) elastic message transmission

6) Not an overly complex C-derivative Language

7) obj-c and c ++ Mixed Programming

Disadvantages of obj-c:

1) namespaces are not supported

2) Operator Overloading is not supported.

3) Multi-inheritance is not supported.

4) use the dynamic runtime type. All methods are called by functions, so many compilation optimization methods are not used.

10. What does the keyword volatile mean? Three different examples are provided.

A variable defined as volatile means that this variable may be unexpectedly changed, so that the compiler will not assume the value of this variable. Specifically, the optimizer must carefully re-read the value of this variable every time when using this variable, rather than using the backup stored in the register. The following are examples of volatile variables:

1. Hardware registers of parallel devices (for example, Status Registers)

2. Non-automatic variables accessed by an interrupt service subroutine

3. variables shared by several tasks in multi-threaded applications

11. Differences Between Stack and stack

Stacks are automatically managed by compilers and controlled by programmers.

Stack is a continuous memory area and a data structure that is extended to a low address. Stack is a data structure that is extended to a high address and is not sequential stored in a linked list.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.