C基础知识
文章平均质量分 55
ych_ding
这个作者很懒,什么都没留下…
展开
-
C++ operator 的用法 进行隐式转换
#includeusing namespace std;class X{public: operator int() { return 0; }} x;class Y{public: operator X() { return x; }} y;int main(){ //int a = y; /* error Y没有定义该类转换方式 */ int b原创 2013-09-04 21:05:12 · 2431 阅读 · 0 评论 -
const char * 的相关内容
#includeusing namespace std;char a[] = "abc";char b[] = "abc";const char c[] = "abc";const char d[] = "abc";const char *e = "abc";const char *f = "abc";int main(){ printf("a=%x, b=%x, a原创 2013-09-04 20:39:23 · 551 阅读 · 0 评论 -
隐式类型转换
先看下面一段程序,这段程序摘自《C 专家编程》:01#include 02int array[] = {23,34,12,17,204,99,16};03#define TOTAL_ELEMENTS (sizeof(array)/sizeof(array[0]))04 05int main(void)06{07 int d=-1,x;08 /*........原创 2012-04-16 16:30:08 · 284 阅读 · 0 评论 -
数组初始化的疑问
#includeusing namespace std;int main(){ int a[4] = {0}; int b[4] = {1}; return 0;}不知道根本原因是什么原创 2013-09-04 21:17:14 · 435 阅读 · 0 评论 -
检验字符串中是否包含重复字符
问题描述:问题分析:借助额外空间示例代码:bool is_repating_character(char a[], int n){ int index[128] = { -1 }; for(int i = 0; i < n; i++) { if (index[a[i]] > 0) { return fal原创 2014-12-28 22:16:36 · 592 阅读 · 0 评论 -
可变参数宏
基本介绍:__VA_ARGS__ 是一个可变参数的宏,这个可变参数的宏是新的C99规范中新增的,目前似乎只有gcc支持。如下定义#ifndef USE_LOG#define LOG(fmt, ...) do { fprintf(stderr, fmt, ##__VA_ARGS__) ; } while(0)#else#define LOG(fmt, ...) do { i原创 2015-01-10 10:39:58 · 483 阅读 · 0 评论 -
C 语言中随机数的生成
1. 产生n个不重复的随机数字,范围是[0, n)。基本思想:有序数据的随机交换。static int randint(int l, int u){ return l + rand() % (u-l+1);}/* generate n distinct random integer in range [0, n) * the implementation depends on原创 2015-05-02 10:57:23 · 524 阅读 · 0 评论 -
C 语言拼接宏
It is often useful to merge two tokens into one while expanding macros.进行宏展开的时候将两个符号合并成为一个符号是很有用的。 This is called token pasting or token concatenation. 这就叫做符号拼接。The ‘##’ preprocessing operator翻译 2014-12-30 15:13:56 · 3879 阅读 · 0 评论 -
leetcode Longest Substring Without Repeating Characters
问题描述:Given a string, find the length of the longest substring without repeating characters. For example, the longest substring without repeating letters for "abcabcbb" is "abc", which the length is原创 2014-12-26 22:29:37 · 333 阅读 · 0 评论 -
给定一个数字num,问需要几位二进制才能表示
问题描述:给定一个数字num,问需要几位二进制才能表示?问题分析:for (bits = 0; (1原创 2014-12-19 09:07:58 · 477 阅读 · 0 评论 -
统计一个无序数组中出现次数最多的元素
统计一个无序数组中出现次数最多的元素。可以有的一种解法是先对数组排序,所有相同的元素都会集中到一起,再进行一次遍历就能解决问题。问题是时间的复杂度比较大。不满足一些场合下的要求。n个元素的数组,有k个不同的元素。每次都从k个不同的元素中减去1个。最后还是可以找到出现次数最原创 2011-09-21 20:08:47 · 12234 阅读 · 4 评论 -
C语言文件IO操作
函数原型:size_t fread ( void * ptr, size_t size, size_t count, FILE * stream ); 所在头文件 : Read block of data from streamReads an array of count elements, each one with a size of size bytes, from原创 2014-12-20 18:42:41 · 7596 阅读 · 0 评论