c指针
c指针的运算有时候还是很迷惑人的。
例如:
struct student {
int num;
int score;
int length;
};
struct student *pt;
pt = (struct student *) malloc(sizeof(struct student));
pt->num = 1;
pt->score = 90;
pt->length = 3 * sizeof(int);
printf("pt length:%d\n", *pt);
pt = (int *)pt + 1;
printf("pt length:%d\n", *pt);
pt = (int *)pt + 1;之后pt的类型还是struct student,长度还是12。
强制转换类型运算符()的作用是:生成一个int *类型的pt,但是pt原来的类型还是没变,
换句话说就是,强制转换类型运算符只在运算时起作用,并不影响原来的值。
相关文档:
理解c中的序列点
http://blog.chinaunix.net/u1/42826/showart_364176.html
让我们来看看下面的代码:
int i=7;
printf(”%d\n”, i++ * i++);
你认为会返回什么?56?no。正确答案是返回 49?很多人会问为什么?难道不该打印出56吗?在ccfaq中有非常详尽的解释,根本原因在于c中的序列 ......
1.引言
C++语言的创建初衷是“a better
C”,但是这并不意味着C++中类似C语言的全局变量和函数所采用的编译和连接方式与C语言完全相同。作为一种欲与C兼容的语言,C++保留了一部分过程
式语言的特点(被世人称为“不彻底地面向对象”),因而它可以定义不属于任何类的全局变量和函数。但是,C++ ......
利用
下载的这段代码,成功实现了守护进程,原来守护进程是很简单的事情。
在main函数中执行
init_daemon();//初始化为Daemon
就可以把进程变成守护进程
#include
#include
#include
#include
#include
void
init_daemon(void
)
{
int
pid;
int
i;
if
(pid=fork()) ......
// & 与,将指定位置设置为0 | 或,将指定位置设置为1
//注: 只针对纯字母的情况
#include <stdio.h>
#include <string>
int main()
{
char str[6] = "xxing";
std::string str1 = "INGXX";
for(int i = 0; i < 5; i++)
{
str[i] &= 0xdf; ......