Question: My Situation:
-------------

I have learnt Swift for a while and Swift is my only language I've learnt for iOS Development, which means I did not learn Objective-C Systematically. I can just read OC Code a little.

I got a `CGPoint` problem when I tried to translate a OC project to Swift project.

Objective-C Code:
-----------------

```
- (void)drawFramesetter:(CTFramesetterRef)framesetter
   attributedString:(NSAttributedString *)attributedString
          textRange:(CFRange)textRange
             inRect:(CGRect)rect
            context:(CGContextRef)c
{
           .
           .

CTFrameRef frame = CTFramesetterCreateFrame(framesetter, textRange, path, NULL);
CFArrayRef lines = CTFrameGetLines(frame);
NSInteger numberOfLines = CFArrayGetCount(lines);
CGPoint lineOrigins[numberOfLines];  // *** The place I had been obstructed! ***

           .
           .
           .
}

```

My Question:
------------

* I have no idea why this line of code, declared as `CGPoint lineOrigins[numberOfLines]`, have no `*` to create an instance variable, `lineOrigins` ?

My unproven guess is that `CGPoint` is a struct rather than a `Class`, but it's still so mysterious to me that created an instance variable without `*` and `=`.
* Another point confused me is `[numberOfLines]`. Is `[numberOfLine]` an array?
* Please teach me how to translate `CGPoint lineOrigins[numberOfLines];` into Swift or show me some hints.

An big appreciation for your guide and time.

Ethan Joe

Answer: 
It's called undefined behavior, since it's undefined sometimes it works. Yes you can write past a memory block in c, but that's illegal because it invokes undefined behavior, the behavior is therefore not predictable and your program might or might not work.

What you expect from `strcpy()` doesn't happen because `strcpy()` copies as many characters as it finds before the `'\0'` terminating byte, it doesn't care if the destination buffer is large enough, that's something you must be responsible about.

If you want to copy an exact number of bytes (*let's say 5*) you can use

```
memcpy(p, "Hello, this string is very large but it doesn't matter", 5);

```

but beware that `p` is not a valid string after that, because it has no terminating `'\0'`.

You also have 2 other common bad practice that new c programmers do

1. You don't need to cast the return value from `malloc()`.
2. You don't need to use `sizeof(char)` because it's 1 by definition.

So,

```
p = malloc(size);

```

should be enough to allocate space for a `size - 1` characters string.
It seems that it worked but in fact your code invokes undefined behavior. You are writing data to unallocated memory location. 

You should note that in 

```
strcpy(str1, str2);  

```

`strcpy` has no way to check whether the string pointed to by `str2` will fit into the character array `str1`. In your case it will continue to copy the characters from `"Hello, world! How are you?` to past the array `p` points to.