Can You Have a Triple Minus Signs in C Programming? What Does It Mean

What do the plus and minus signs mean in Objective-C next to a method?

+ is for a class method and - is for an instance method.

E.g.

// Not actually Apple's code.
@interface NSArray : NSObject {
}
+ (NSArray *)array;
- (id)objectAtIndex:(NSUInteger)index;
@end

// somewhere else:

id myArray = [NSArray array]; // see how the message is sent to NSArray?
id obj = [myArray objectAtIndex:4]; // here the message is sent to myArray

// Btw, in production code one uses "NSArray *myArray" instead of only "id".

There's another question dealing with the difference between class and instance methods.

What is &&& operation in C

It's c = i && (&i);, with the second part being redundant, since &i will never evaluate to false.

For a user-defined type, where you can actually overload unary operator &, it might be different, but it's still a very bad idea.

If you turn on warnings, you'll get something like:

warning: the address of ‘i’ will always evaluate as ‘true’

What does the operation c=a+++b mean?

It's parsed as c = a++ + b, and a++ means post-increment, i.e. increment after taking the value of a to compute a + b == 2 + 5.

Please, never write code like this.

What does output indicate when larger address is subtracted from smaller address in C/C++ programming?

The problem in your code is that you have undefined behaviour. Not because of the pointer arithmetic but because you are printing signed integers using the %u format specifier. Change to the %td format (the t to specify a 'pointer difference' type) and you will see more meaningful results:

#include <stdio.h>
#include <stddef.h>

int main()
{
int a[5];
printf("%td\n", &a[3] - &a[0]); // Shows "3"
printf("%td", &a[0] - &a[3]); // Shows "-3"
return 0;
}

From this C11 Draft Standard (Section 6.5.6 Paragraph #9) (bolding mine):

When two pointers are subtracted, both shall point to elements of the
same array object, or one past the last element of the array object;
the result is the difference of the subscripts of the two array
elements. The size of the result is implementation-defined, and its
type (a signed integer type) is ptrdiff_t defined in the <stddef.h>
header ...



Related Topics



Leave a reply



Submit