寥寥数笔,记录我的C语言盲点笔记,仅仅为以前经历过,亦有误,可交流。1.逻辑表达式的使用取值 = 表达式 ? 表达式1:表达式2;比方x = y > z ?y:z2."+,-"等逻辑运算符优先级大于移位,移位大于逻辑运算3.sizeof在编译时由编译器完毕,对其传入的參数不做运算处理。sizeof(...
分类:
编程语言 时间:
2014-07-22 22:57:15
阅读次数:
260
int main()
{
int A[] = { 1, 2, 3, 3, 3, 5, 8 };
const int N = sizeof(A) / sizeof(int);
for (int i = 1; i <= 10; ++i) {
cout << "Searching for " << i << ": "
<< (binary_search(A, A + N, i) ? "present" : "not present") << endl;
}
}
/*
...
分类:
其他好文 时间:
2014-07-19 23:29:59
阅读次数:
275
题目简单的计算A,B之间有多少个素数只是测试数据有是负的//AC//A和B之间有多少个素数//数据可能有负的!!!#include#include//素数筛选法int pri[100000+10];//1 合数, 0 素数void Prime(){ memset(pri,0,sizeof(pr...
分类:
其他好文 时间:
2014-07-19 20:04:10
阅读次数:
266
一个天天跟c#奋斗的苦逼c++程序员 改自己以前代码的时候发现有如下几行.
char szPath[MAX_PATH] = {0};
GetModuleFileNameA(NULL,szPath,sizeof(szPath));
std::string strPath = szPath;
std::string strDir = strPath.substr(0,strPa...
分类:
其他好文 时间:
2014-07-18 22:24:31
阅读次数:
187
1. 用new 运算符实现动态内存分配第一种用法,分配一个变量:P = new T; T是任意类型名,P是类型为T * 的指针。 动态分配出一片大小为 sizeof(T)字节的内存空间,并且将该内存空间的起始地址赋值给P。比如:int * pn;pn = new int; * pn = 5;第...
分类:
编程语言 时间:
2014-07-16 18:39:49
阅读次数:
193
- (NSString *)getLocalIP{
struct sockaddr_in sa;
socklen_t len = sizeof(sa);
if(getsockname(sockfd, (struct sockaddr *)&sa, &len))
{
NSLog(@"获取失败!");
}
return [NSS...
分类:
移动开发 时间:
2014-07-16 17:24:41
阅读次数:
238
Size of Data TypesAlways use sizeof() to get the size of types(sizeof(char), sizeof(short), sizeof(int)...)Do not depend on the order of evaluation in...
分类:
其他好文 时间:
2014-07-16 15:51:58
阅读次数:
191
void func(char arr[100]){ coutusing namespace std;void myF( char arr[100]){ cout<<sizeof(arr)<<endl;}int main(void){ char arr[100]; myF(a...
分类:
编程语言 时间:
2014-07-13 21:15:06
阅读次数:
175
先来个简单的例子
int a[] = {1,2,3};
int arr_len = 0;
arr_len = sizeof(a)/sizeof(int);
解释:sizeof() 关键字是求出对象所占用的内存空间的大小,so, sizeof(a)是算出整个数组占用的空间的大小。
因为是整数数组,一个整数在32位系统上占用4个字节,不同的系统数值可能不同, 用sizeof(int)...
分类:
编程语言 时间:
2014-07-12 18:45:18
阅读次数:
179