相关疑难解决方法(0)

指向数组/指针数组的C指针消歧

以下声明之间有什么区别:

int* arr1[8];
int (*arr2)[8];
int *(arr3[8]);
Run Code Online (Sandbox Code Playgroud)

理解更复杂的声明的一般规则是什么?

c arrays pointers variable-declaration

451
推荐指数
6
解决办法
38万
查看次数

必须在使用前初始化指针,然后如何理解char*p?

新学员; 关于指针的一些难题;

当我从书本中学习时,在使用指针之前必须对其进行初始化,因此我们通常会这样使用

int a = 12;

int * p = &a; 
Run Code Online (Sandbox Code Playgroud)

所以我明白为什么int* p = 12 是错的,因为它没有地址;

然后我在编码的时候找到了一些东西,就是这样:

char * months[12] = {"Jan", "Feb", "Mar", "April", "May" , "Jun", "Jul"    
,"Aug","Sep","Oct","Nov","Dec"};
Run Code Online (Sandbox Code Playgroud)

然后又出现了另一个常用的情况,那就是:

char *p = "string"; (this is ok , why int * a = 12 can't be allowed ?)
Run Code Online (Sandbox Code Playgroud)

我很困惑.什么时候初始化,如何?为什么int * a = 12不能自动初始化?也许是关于记忆的安排.

c c++ pointers

4
推荐指数
1
解决办法
394
查看次数

从一天中的小时数返回打开,关闭或关闭的功能

我有一堆小时的操作我想确定商店是开放,关闭还是在30,29,28,27 ......我关闭的时间我在Xcode/Objectic-C中这样做.现在我必须这样做,让我们说50个小时的操作.我已经创建了一个函数来执行此操作,但它效率不高并且涉及很多if-else语句.这是一个小时的操作样本

Monday - Thursday
7:30am - Midnight
Friday
7:30am - 10:00pm
Saturday
9:00am - 10:00pm 
Sunday
9:00am - Midnight 
Run Code Online (Sandbox Code Playgroud)

这是我的功能以及我如何处理它

-(BOOL) dateAndTime:(NSDate*)date getStartDay:(NSInteger)startDay getStartHour:(NSInteger)startHour getStartMin:(NSInteger)startMin getEndDay:(NSInteger)endDay getEndHour:(NSInteger)endHour getEndMin:(NSInteger)endMin{

    NSCalendar *calendar = [NSCalendar currentCalendar];


    const NSCalendarUnit units = NSWeekdayCalendarUnit | NSHourCalendarUnit | NSMinuteCalendarUnit;
    NSDateComponents *comps = [calendar components:units fromDate:date];

    if (comps.weekday == 1) {
        comps.weekday = 7;
    }
    else comps.weekday = comps.weekday - 2;

    NSDate *startOfToday;
    [[NSCalendar currentCalendar] rangeOfUnit:NSDayCalendarUnit startDate:&startOfToday interval:NULL forDate:date];

    NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
    NSTimeZone *timeZone …
Run Code Online (Sandbox Code Playgroud)

time xcode date objective-c ios

4
推荐指数
1
解决办法
584
查看次数

标签 统计

c ×2

pointers ×2

arrays ×1

c++ ×1

date ×1

ios ×1

objective-c ×1

time ×1

variable-declaration ×1

xcode ×1