由买买提看人间百态

topics

全部话题 - 话题: pointer
首页 上页 1 2 3 4 5 6 7 8 9 10 下页 末页 (共10页)
m****s
发帖数: 1481
1
我需要读取一个数据文件,然后把读出来的数据放到不同的变量里,因为这些变量的长
度不确定,所以都是临时根据长度分配内存,code如下:
... main(){
...
...
int *a,length_a;
double *d,length_d;
char *c,length_c;
FILE *fp;
... 打开文件代码...
...读文件,获取变量a,d,c的长度...
a= new int[length_a];
d= new double[length_d];
c= new char[length_c];
...计算,处理...
delete[] a;
delete[] d;
delete[] c;
}
这种最基本的方法运行没问题。
现在因为我要load的变量很多,所以我想把loading用一个函数来做。如果只有一个变
量,我可以把它的pointer定义在main里面,然后用一个函数读取文件,在函数里
declare一个临时pointer,分配内存,赋值,然后返回这个pointer。
但是如果多个变量的情况怎么做呢?
我先试了把多个变量的指针传递给子函数,在子函数里declare... 阅读全帖
S*****H
发帖数: 90
2
1. What is Object?
2. What is Polymorphism? How to implement polymorphism?
3. What is Dynamic Binding and Static Binding?
4. What is OOP?
5. What are important features of OOP? Why OOP are better?
6. What is Class?
7. Difference between class and object.
8. What is enum? What is enum's limitation?
9. What are interface and abstract class?
10. How would you choose between an abstract class and interface?
11. What are struct and union?
12. What is the difference... 阅读全帖
S*****H
发帖数: 90
3
1. What is Object?
2. What is Polymorphism? How to implement polymorphism?
3. What is Dynamic Binding and Static Binding?
4. What is OOP?
5. What are important features of OOP? Why OOP are better?
6. What is Class?
7. Difference between class and object.
8. What is enum? What is enum's limitation?
9. What are interface and abstract class?
10. How would you choose between an abstract class and interface?
11. What are struct and union?
12. What is the difference... 阅读全帖
e****e
发帖数: 418
4
来自主题: JobHunting版 - 一道题目

Thanks for your idea, erYe. Here is the code.
public static int findMaxInEveryArray(int[][] m) {

if ( m == null || m.length == 0 )
return -1;

int[] pointers = new int[m.length];
for( int i = 0; i < m.length; i++ ){
if ( m[i] == null || m[i].length == 0 ) {
return -1;
}
pointers[i] = m[i].length -1;
}

while ( true ) {
if ( isAllEqual( m, pointers ) )
... 阅读全帖
r**h
发帖数: 1288
5
来自主题: JobHunting版 - 一点码工求职经验总结,回报本版
个人总结的一些C/C++问题:
C Tutorial:
http://www.cprogramming.com/tutorial.html
C问题集:
http://www.indiabix.com/technical/c/
http://www.parashift.com/c++-faq-lite/index.html
1) 为啥要用c++;
2) encapsulate, polymorphism ,inheritance 的概念;
encapsulate: Hide details of implementation
polymorphism : has multiple forms
inheritance: is-a relationship
3)class的概念
type of object
4)default constructor是啥样的;
without parameters
5) 写copy  constructor要注意啥
parameter must be reference : Node(const... 阅读全帖
d**********o
发帖数: 1321
6
来自主题: WebRadio版 - 潜水员冒泡兼征版友意见
第一个项目report
这时偶刚到CSAC工作不久,与小A同学还不熟,我用的还是latex。随着贴的作业越来越
多,应该是用有共同爱好的小伙伴更亲密些。这次贴latex,下次才再org-mode。
\documentclass[b5paper,11pt, abstraction, titlepage]{scrartcl}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{CJKutf8}
\usepackage{multirow}
\usepackage{multicol}
\usepackage{listings}
\usepackage{geometry}
\geometry{b5paper}
\usepackage{graphicx,floatrow}
\usepackage{graphicx,subfigure}
\newsavebox{\abstractbox}
\renewenvironment{abstract}
{\begin{lrbox}{0}\begin{minipage}{\t... 阅读全帖
d**********o
发帖数: 1321
7
来自主题: WebRadio版 - 潜水员冒泡兼征版友意见
第一个项目report
这时偶刚到CSAC工作不久,与小A同学还不熟,我用的还是latex。随着贴的作业越来越
多,应该是用有共同爱好的小伙伴更亲密些。这次贴latex,下次才再org-mode。
\documentclass[b5paper,11pt, abstraction, titlepage]{scrartcl}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{CJKutf8}
\usepackage{multirow}
\usepackage{multicol}
\usepackage{listings}
\usepackage{geometry}
\geometry{b5paper}
\usepackage{graphicx,floatrow}
\usepackage{graphicx,subfigure}
\newsavebox{\abstractbox}
\renewenvironment{abstract}
{\begin{lrbox}{0}\begin{minipage}{\t... 阅读全帖
B*******1
发帖数: 2454
8
来自主题: JobHunting版 - 回文数的问题
不好意思,没有解释清楚
因为现在回文数肯定是偶数,那么就假设每次读进2个字符
假设数字到prime的mapping为
1->2
2->3
3->5
4->7
5->9
...
用你的例子123123,
1.读入12, slow pointer指向1,fast pointer 指向2, slow pointer指向的数包括之
前的数对应的primes number乘积为2, fast pointer的为6
2. 读入31, slow pointer指向2,fast pointer 指向1, slow pointer指向的数包括
之前的数对应的乘积为6, fast pointer的为60
3。读入23, slow pointer指向3,fast pointer 指向3, slow pointer指向的数包括
之前的数对应的乘积为30, fast pointer的为90 = 30*30, 调用如下function check
到目前为止的stream是不是回文
private boolean test(int[] a, int i) {
for (int j=0; j<... 阅读全帖
d****n
发帖数: 1637
9
来自主题: Programming版 - 分享:Go语言黑魔法(内存)
http://zhuanlan.zhihu.com/thought/20010926
达达 · 6 天前
今天我要教大家一些无用技能,也可以叫它奇技淫巧或者黑魔法。用得好可以提升性能
,用得不好就会招来恶魔,嘿嘿。
黑魔法导论
为了让大家在学习了基础黑魔法之后能有所悟,在必要的时候能创造出本文传授之外的
属于自己的魔法,这里需要先给大家打好基础。
学习Go语言黑魔法之前,需要先看清Go世界的本质,你才能获得像Neo一样的能力。
在Go语言中,Slice本质是什么呢?是一个reflect.SliceHeader结构体和这个结构体中
Data字段所指向的内存。String本质是什么呢?是一个reflect.StringHeader结构体和
这个结构体所指向的内存。
在Go语言中,指针的本质是什么呢?是unsafe.Pointer和uintptr。
当你清楚了它们的本质之后,你就可以随意的玩弄它们,嘿嘿嘿。
第一式 - 获得Slice和String的内存数据
让我小试身手,你有一个CGO接口要调用,需要你把一个字符串数据或者字节数组数据
从Go这边传递到C那边,比如像这个:mysql/con... 阅读全帖
q****x
发帖数: 7404
10
来自主题: JobHunting版 - 谁对design pattern比较熟?
1st:
"In computer science, a smart pointer is an abstract data type that
simulates a pointer while providing additional features, such as
automatic garbage collection or bounds checking. These additional
features are intended to reduce bugs caused by the misuse of pointers
while retaining efficiency. Smart pointers typically keep track of the
objects they point to for the purpose of memory management."
2nd:
"Smart pointers are objects that look and feel like pointers, but are
smarter. What does ... 阅读全帖
N*****8
发帖数: 253
11
来自主题: JobHunting版 - 问道电面算法题
google搜了一下的答案,前提是有range,而且是n+1的元素,但是不用加法解,不会溢
出:
Solution: (by Ovidiu Gheorghioiu at Google) Treat the values of the array as
pointers into the same array. Let us call a chain of pointers a “linked
list”. The linked list starting with the last entry must have the shape of
a “lollipop” with a stick and a cycle. Our goal is to identify that node
in the linked list that joins the stick to the cycle. We do so in two phases:
Phase I: maintain two pointers, one ‘slow’ and one ‘fast’. In one round,
the... 阅读全帖
d**********o
发帖数: 1321
12
来自主题: WebRadio版 - 潜水员冒泡兼征版友意见
第二次作业report
#+latex_class: cn-article
#+latex_header: \usepackage{CJKutf8}
#+latex_header: \begin{CJK}{UTF8}{gbsn}
#+latex_header: \lstset{language=c++,numbers=left,numberstyle=\tiny,
basicstyle=\ttfamily\small,tabsize=4,frame=none,escapeinside=``,
extendedchars=false,keywordstyle=\color{blue!70},commentstyle=\color{red!55!
green!55!blue!55!},rulesepcolor=\color{red!20!green!20!blue!20!}}
#+title: CS572 Project 2 Report
#+author: (me~~~)
#+begin_abstract
|---------------------------+------------... 阅读全帖
d**********o
发帖数: 1321
13
来自主题: WebRadio版 - 潜水员冒泡兼征版友意见
第二次作业report
#+latex_class: cn-article
#+latex_header: \usepackage{CJKutf8}
#+latex_header: \begin{CJK}{UTF8}{gbsn}
#+latex_header: \lstset{language=c++,numbers=left,numberstyle=\tiny,
basicstyle=\ttfamily\small,tabsize=4,frame=none,escapeinside=``,
extendedchars=false,keywordstyle=\color{blue!70},commentstyle=\color{red!55!
green!55!blue!55!},rulesepcolor=\color{red!20!green!20!blue!20!}}
#+title: CS572 Project 2 Report
#+author: (me~~~)
#+begin_abstract
|---------------------------+------------... 阅读全帖
r*******y
发帖数: 1081
14
来自主题: Programming版 - 一个nested class的问题
thinking in c++ 里面有关于 nested friend class的一个例子,不知道有没有帮助。
//: C05:NestFriend.cpp
// Nested friends
#include
#include // memset()
using namespace std;
const int sz = 20;
struct Holder {
private:
int a[sz];
public:
void initialize();
struct Pointer;
friend struct Pointer;
struct Pointer {
private:
Holder* h;
int* p;
public:
void initialize(Holder* h);
// Move around in ... 阅读全帖
b******p
发帖数: 49
15
我也买了一台这个…
是20DM009GUS的翻新版,订单上虽然写的是20DMX005UUS,但是在BIOS里看到的是
20DM009GUS。是有触摸和Active Pen的:
$ xinput
⎡ Virtual core pointer id=2 [master pointer
(3)]
⎜ ↳ Virtual core XTEST pointer id=4 [slave
pointer (2)]
⎜ ↳ Wacom HID Finger touch id=10 [
slave pointer (2)]
⎜ ↳ Wacom HID Pen stylus id=11 [
slave pointer (2)]
⎜ ↳ AlpsPS/2 ALPS DualPoint... 阅读全帖
B*******1
发帖数: 2454
16
来自主题: JobHunting版 - 回文数的问题
我把1-10 每一个数字对应一个质数
保持两个pointer,一个slow pointer,一个fast pointer, slow pointer 一直指向已
得到数据流中间,fast pointer 指向最新数据流,保持两个值,一个slow pointer 之
前的所有数字对应的prime number的乘积,一个对应fast pointer之前所有数字对应
prime number的乘积,当fast pointer的乘积 = slow pointer的乘积的平方的时候,
调用你那个rolling hash里面的test function来确认是不是
这样子可以吗?
S**I
发帖数: 15689
17
☆─────────────────────────────────────☆
gzou (gzou) 于 (Thu May 12 02:26:35 2011, 美东) 提到:
马上就要G on site了,
求祝福。
下面是从本版收集到的Google的试题,便于大家查询。
申明:有的附带有解释说明的,也来自于本版或者网络,大家自己看, 不保证真确
http://www.mitbbs.com/article_t1/JobHunting/31847453_0_1.html
本人ECE fresh PhD,背景是电路/EDA,跟G业务基本没什么关系
同学内部推荐的,很简单的一次电面就给了onsite
题都不难,但是自己没把握好机会,出了一些小bug。
总的感觉,出错就是硬伤,宁可从最简单的算法写起,也不能出错。
电面:
1,Skip list, http://en.wikipedia.org/wiki/Skip_list
写code实现struct skip_list * find(struct skip_list *head, int value)
2,sorted array... 阅读全帖
S**I
发帖数: 15689
18
☆─────────────────────────────────────☆
gzou (gzou) 于 (Thu May 12 02:26:35 2011, 美东) 提到:
马上就要G on site了,
求祝福。
下面是从本版收集到的Google的试题,便于大家查询。
申明:有的附带有解释说明的,也来自于本版或者网络,大家自己看, 不保证真确
http://www.mitbbs.com/article_t1/JobHunting/31847453_0_1.html
本人ECE fresh PhD,背景是电路/EDA,跟G业务基本没什么关系
同学内部推荐的,很简单的一次电面就给了onsite
题都不难,但是自己没把握好机会,出了一些小bug。
总的感觉,出错就是硬伤,宁可从最简单的算法写起,也不能出错。
电面:
1,Skip list, http://en.wikipedia.org/wiki/Skip_list
写code实现struct skip_list * find(struct skip_list *head, int value)
2,sorted array... 阅读全帖
e*******8
发帖数: 94
19
来自主题: JobHunting版 - service now 卧佛和面筋
cong~
那个检查linked list是不是palindrome的,我觉得可以这么做:用slow/fast
pointer的方法,slow pointer向前移动的同时把linked list反转(反转之前包存/更
新slow pointer之后的那个结点);等fast pointer到达linked list的end的时候,
slow pointer就应该指向linked list中间的结点;然后从linked list中间向两边移动
:slow pointer向左移动,slow pointer之后的那个指针向右移动,每一步比较指向的
key是否相同。移动slow pointer的同时再反转linked list。等slow pointer移动到末
尾,linked list也就恢复了。
觉得这题面试的时候要写的bug free,感觉还挺难的。。。。
e*******n
发帖数: 23
20
来自主题: JobHunting版 - stream palindrome
set 2 pointer. 1st pointer move 1 char each time. 2nd pointer move 2 char
each time. when the 2nd pointer reach the end, the 1 st pointer is in the
middle of stream. then now set 2 pointers in this middle. 1 pointer go left
each time and another one go right and check if these 2 pointer always point
to same char.
z****e
发帖数: 2024
21
来自主题: Programming版 - 求C/C++面试题
C++我给你出一招,这个阿三基本就挂了,
你就问他关于 pointer-to-member function 的一些,
1. 语法,让他写一个指向普通成员函数的,
2. static 成员函数的pointer,还有 virtual ,普通的成员函数pointer,三者如何类型转化,可不可以类型转化,那些可以,那些不可以,为什么。
3. 2中详细一点的,就是把基类的pointer-to-member function赋值给派生类的pointer-to-member function,行不行,反过来行不行,为什么?这个有个专门的术语,叫什么。
4. pointer-to-member function 对于virtual, static, non-virtual and non-static, 都有什么本质上边的不用,pointer-to-member function到底代表了什么,是地址,还是相对地址,还是分情况讨论的。
5.比如一个class A的object a,还有一个class B的object b,然后定义一个pointer-to-member function指向A里边的一
f*******n
发帖数: 12623
22
一个const是关于pointer指向的那些char。另一个是关于pointer变量本身。
const char *
char const *
这两个是一样的。就是说pointer本身可以变,但是不能通过pointer来改指向的char。
char * const
这是说pointer本身不能变,但是可以通过pointer来改指向的char。
const char * const
char const * const
这两个是一样的。就是说pointer本身不能变,也不能通过pointer来改指向的char。
c*********u
发帖数: 361
23
来自主题: JobHunting版 - 一道老题
网上找到的答案:
I would do this as a two-pass process. The first step would be to create the
complete linked list using the next pointers. At the time you are doing tha
t you'll want to construct a vector of pairs to pointers - the first pointer
being the original node in A and the second pointer being its equivalent no
de in B. The second pass of the algorithm will be to map the random pointers
in B from the original A-node pointer to their equivalent B-node pointers u
sing the map created in the firs
I**********s
发帖数: 441
24
来自主题: JobHunting版 - Google点面
问了1) 研究, 2) 多线程程序设计, 3) 任意无穷字符串流, 内存有限, 找出唯一一对
重复字符串, 这个我说了哈希表和外部排序, 但是面试人说有更好的办法(后来想也许
是bloom filter), 然后追问外部排序的细节到结束. 估计要挂 :(
总结: 面试既是技术活, 又是运气活.
无论如何, 把我的准备工作放下面, 攒点rp, 希望对大家有所帮助.
Interview Qs
Data Structures
1. Integer
- find number of 1s
- next largest smaller
- smallest larger number
- determine if is palindrom
- itoa, atoi
- add 2 numbers w/o using + or arithmetic operators
- implement *, -, / using only +
- find max of two numbers w/o co... 阅读全帖
I******c
发帖数: 163
25
来自主题: JobHunting版 - LinkedIn onsite一道题
我的java实现,参考了Blaze的思路,不过不知道真正理解了他的思路没有,因为我不
太看得懂javascript.下面是几个点:
1. 这个题目用的是backtracking而不是dp,因为dp不可能给你产生排列组合。dp通常
就是给你一个最值。
2. 时间复杂度是指数级。
3. 题目的本质是产生排列。
4. 一般的backtracking来形成字符串的话,从现有字母集中每次任意挑一个字母,然后
从剩下的字母里继续挑。把所有字母都加到字符串里面去了,这轮程序也就完了。这个
题目因为有个顺序的限制条件,决定程序怎样进行下去并不能用剩下多少字符来决定,
而应该是用已经加入字符串的字母的位置来决定。
import java.util.HashMap;
import java.util.List;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.Set;
public class Example5 {
public static void main(String [] args){
... 阅读全帖
W*******s
发帖数: 18705
26
来自主题: Fishing版 - 惊涛小论--再谈Jerkbait。
Jerkbait就是瘦长鱼形带二个或三个三股钩的硬饵。Jerkbait有漂浮,悬浮,缓沉,缓
升四种特性。每家厂家的标准不一样,低温冷水的比重比较高,本来悬浮完美的饵会缓
升。不伦是缓升或缓沉,这种起伏要越细微越好(Subtle)。置于到底是缓沉好还是缓
升好,普肉也各有各的说法,一般来说,冷水是缓沉比较好,温水是缓升为妙。具体如
何,一方水土一方鱼,这个还真不好说。通常是追求完美悬浮--不升也不降。如果一枚
Jerkbait上升太快,第一个方法是把钩子换成大一号的,如果这个方法效果不明显,那
就用铅丝绕钩子。如果一枚Jerkbait下沉太快,这个问题比较麻烦,换小号的钩子不适
合,因为Jerkbait的钩子本来就比较小,可以考虑用尺寸一样的短杆细钩,或是用较粗
的尼龙线代替的碳线。
使用Jerkbait的条件:
漂浮形的Jerkbait用于适合水面系列饵使用的天气水温条件。多数人认为Jerkbait是春
天/秋天最好用,我认为任何时候都可以用。第一,水色要清,或是半清,第二,要有
水深。我知道很多人岸钓用Jerkbait很失败,原因就是岸钓抛投距离内比较少有适合的
水深玩Jerkba... 阅读全帖
X****r
发帖数: 3557
27
来自主题: Programming版 - int (*b)[2]; 是什么意思?
Frankly I never get what is so hard about reading variable declarations.
As long as you can read C expressions, you can read variable declarations.
e.g. int (*b)[2] => (*b)[2] is a int.
So (*b) is an array of 2 ints, and b is a pointer to an array of 2 ints.
The same operator precedence applies here, too.
Another slightly more complex example
double (*(*f)(int (*)(int)))(double);
==> (*(*f)(int (*)(int)))(double) is a double
==> (*(*f)(int (*)(int))) is a function from a double to a double
==> (... 阅读全帖
d****n
发帖数: 1241
28
来自主题: Programming版 - 问个c++ struct和指针问题
* 首先,struct的大小依赖于两个因素,一是field的大小,二是field的alignment,
这两个都是由ABI决定的,比如在64位的机器上,如果编译器选择遵守gcc/llvm所支持
的x86_64 ABI标准,那么double是8byte对齐,如果在32位的机器上,linux下gcc支持
的x86 abi是4byte对齐. 大小的话,double类型都是8 bytes. 在缺省情况下,如果某
个field不符合对齐标准,那么编译器会插入padding bytes,让这个field符合对齐的
标准。比如:
struct S {
char f1; // size是1,对齐是1
int f2; // size是4,对齐也是4
};
sizeof(struct S)是8,因为编译器会在f1后,加入3个padding bytes, 让f2符合对齐
的规范。
* 如果在定义struct的时候,添加了类似packed的attribute, 那么编译器会忽略对齐
的要求。
* auto跟动态类型没有关系,在你的例子里,pointer类型是编译器在静态的时候,根
据一定的类型推导规... 阅读全帖
h********l
发帖数: 67
29
1 . 用预处理指令#define 声明一个常数,用以表明1年中有多少秒(忽略闰年问题)
2 . 写一个"标准"宏MIN ,这个宏输入两个参数并返回较小的一个。
3. 预处理器标识#error的目的是什么?
4. 嵌入式系统中经常要用到无限循环,你怎么样用C编写死循环呢?
5. 用变量a给出下面的定义 a) 一个整型数(An integer) b)一个指向整型数的指针
( A pointer to an integer) c)一个指向指针的的指针,它指向的指针是指向一个
整型数( A pointer to a pointer to an intege)r d)一个有10个整型数的数组(
An array of 10 integers) e) 一个有10个指针的数组,该指针是指向一个整型数的
。(An array of 10 pointers to integers) f) 一个指向有10个整型数数组的指针
( A pointer to an array of 10 integers) g) 一个指向函数的指针,该函数有一
个整型参数并返回一个整型数(A pointer to a fun
n***r
发帖数: 105
30
来自主题: JobHunting版 - 问到linked list 的题目
很close了。我觉得这题是考pointer's pointer。
但我觉得怎么招都得知道前一个node的地址,得把其next pointer赋值为NULL,否则就
断链了。用pointer's pointer的好处是在遍历这个linked list的时候可以省去一个指向前一
个node的pointer。
比如说删除存有item为i的程序就可以这样写,但是还是require work through这个
list,以便持有前一个node的地址。
struct list **lpp;
for(lpp = &list; *lpp != NULL; lpp = &(*lpp)->next)
{
if((*lpp)->item == i)
{
*lpp = (*lpp)->next;
break;
}
}
}

用这段程序,就算删除的对象是尾node,也自动take care了。欢迎讨论
w******f
发帖数: 620
31
来自主题: JobHunting版 - c++ 程序一问
Another way is you could just change the test to return char * and return
the p, it will work. But you need remember to delete the pointer after you
finished.
Basically when you pass the pointer into the function, in function stack
memory, it will copy the value of pointer, it don't change anything about
the pointer itself, it could change the value this pointer pointer to, but
if you dynamic allocate memory and assign to p, then p hold different value,
it does nothing to do with the original P.
i**********e
发帖数: 1145
32
来自主题: JobHunting版 - sorted linked list里insert一个node
请看我之前发过的帖子:
http://www.mitbbs.com/article_t0/JobHunting/31881903.html
看下12楼我贴的图片,可以对 pointer to pointer 的理解更进一步。
这个方法很巧妙,在很多情况下可以用,例如:
1)linked list insertion,就如 lz 说的.
2)linked list merge/intersection
3)BST insert (iterative)
如果不用 pointer to pointer,那以上的程序一就是需要利用递归,二就是因为处理
个别状况而写起来很繁琐。
以下是一个使用的例子:
Node *head = NULL; // this will be the result stored in linked list
Node **p = &head; // pointer to pointer used to advance the result
......
// to insert new node to p.
*p = new Node(val);
p = &((... 阅读全帖
c**********e
发帖数: 2007
33
来自主题: JobHunting版 - C++ Q93 - Q95
C++ Q93: formal parameter T
What is the purpose of declaring the formal parameter T?
A. T specifies that any data sent to the function template must be of type T
B. T is a place-holder for a C++ data type
C. T can only hold a single data type int
D. T can hold any language data type
C++ Q94: Pointer
Multiple choices: Identify the true statements about the use of pointers in
C++.
A. A pointer is a variable that can contain the memory address of another
variable as its value
B. Although not necess... 阅读全帖
c**********e
发帖数: 2007
34
来自主题: JobHunting版 - C++ Q93 - Q95
Q94 Answer: A and C.

C++ Q94: Pointer
Multiple choices: Identify the true statements about the use of pointers in
C++.
A. A pointer is a variable that can contain the memory address of another
variable as its value
B. Although not necessary, pointers make the use of dynamic memory
allocation more efficient
C. You can use casting to cause a pointer of one type to reference the
memory address of a variable of another type
D. In a cout statement, you can use a pointer to display a memory address,
... 阅读全帖
S**I
发帖数: 15689
35
来自主题: JobHunting版 - [合集] 问个C的基本问题
☆─────────────────────────────────────☆
honeydream (pretty) 于 (Fri May 6 00:30:21 2011, 美东) 提到:
下面这个程序为啥会segmentation fault呢?
int main(void)
{
char *p1, *p2;
*p1 = 'a';
*p2 = 'b';
printf("%c %c\n", *p1, *p2);
return 0;
}
如果我不用指针,把p1,p2的星号都去掉,就可以输出正确结果。
☆─────────────────────────────────────☆
chenpp (chenpp) 于 (Fri May 6 00:31:43 2011, 美东) 提到:
p1和p2浮空,指向未定义的地址空间。
对未定义的地址空间进行读写操作会导致未定义的行为,包括段错。

☆─────────────────────────────────────☆
mercuriusl (Mercurius) 于 (Fri May 6 ... 阅读全帖
b****n
发帖数: 464
36
Keep 
track 
of
 two 
pointers 
in the linked&
#8233; list,
 and 
start 
them
 at 
the

beginning 
of 
the 
linked 
list.


At 
each 
iteration 
of 
the 

algorithm,
advance 
the 
first
 pointer 
by
one 
node 
and 
the
 second
 pointer by

two 
nodes.


If 
the 
two ̷... 阅读全帖
c*******t
发帖数: 1095
37
来自主题: JobHunting版 - 问求array中3个数和最接近k的解法
O(n^2)下面这段code有反例么? 没想出来反例

for(each ele in the sorted array)
{
ele = arr[i] - k;
let front be the pointer to the front of the array;
let rear be the pointer to the rear element of the array.;
// till front is not greater than rear.
while(front <= rear)
{
if(*front *rear == ele)
{
print "Found triplet "<<*front<<","<<*rear<<","< break;
}
else
{
// sum is > ele, so ... 阅读全帖
J****3
发帖数: 427
38
来自主题: JobHunting版 - 麻烦2爷peking2帮个忙
试着写写, 楼主看看, 大家一起总结:
1. Clone Graph-> BFS+HashMap
2. Gas Station->DP
3. Candy->Two Pointers
4. Single Number-> Xor, HashMap, or Sum or Product way to find
5. Single Number II -> Xor, HashMap
6. Copy List with Random Pointers -> Two Pointers, HashMap with two times
traverse(like clone graph)
7. List Cycle, List Cycle II, Reorder List-> Two Pointers
8. Binary Tree Preorder, Postorder recursive -> Using stack to mock
recursive way, or implement like morris way.
9. LRU Cache-> HashMap + list
10. Inse... 阅读全帖
g****s
发帖数: 1755
39
来自主题: Basketball版 - ZT: Is it time to move the 3 point line back
Is it time to move the NBA’s 3-point line back? Has the shot become too
easy and too frequent in today’s game?
From an analytical perspective, the 3-point shot is one of the most
important scoring options on the court. But is it too easy for contemporary
players? During the Finals, the Spurs made an incredible 47 percent of their
3s, which translates to 1.41 points per shot. It’s no wonder they
attempted a third of their shots from beyond our magical point-inflating arc
. The Heat weren’t too fa... 阅读全帖
z**********i
发帖数: 9546
40
来自主题: NBA版 - 武器库对比《虎扑转载》
https://bbs.hupu.com/20117953.html
图在链接网页
----------------------------------------------------
[美国JRs之声]武器库对比,威少更刚猛,哈登万金油,库里惨遭调戏!
由 全宝蓝是我的丶 发表在虎扑篮球·湿乎乎的话题 https://bbs.hupu.com/vote
[OC] 18/50: Comparing the scoring versatility of Westbrook, Harden, and
Curry (i.imgur.com)
对威少、哈登和库里各种得分手段进行的比较。
【注】图中纵轴为进攻方式的每回合得分,横轴各项从左至右依次分别是:混合进攻、
作为持球人发动挡拆、单打、背身、手递手、无球掩护、定点投篮、补篮、转换进攻、
空切。
Notes
All data from NBA.com.
Data is from the 2016-17 regular season.
I included all play types except P&R Roll Man becaus... 阅读全帖
l******8
发帖数: 9475
41
下面观点纯属个人观点.
为了增加获奖犬数, 吸引更多人来参赛, 把当前的有些组分裂成一个以上的组.
设想是从7个组变成11个组.
当前的组:
http://topshowdogs.com/SelectAKC.aspx
http://www.akc.org/breeds/toy_group.cfm#
以后可能的组: (转自AKC网站)
http://www.akc.org/pdfs/news/Realignment_SuggestedBreedList.pdf
The Groups – projections with breeds currently in the Groups, Miscellaneous
Class and Foundation Stock Service
(numbers based on inclusion of new breeds and some movement within the
groups, as some breeds are recommended for reassignment)
Group 1: Sporting – Pointers ... 阅读全帖
d****p
发帖数: 685
42
来自主题: Programming版 - shared_ptr处理stack上面的指针
pi is not initialized to a pointer to variable allocated on heap. and it is
even not initialized to 0.
so either
....boost::shared_ptr spi(new int 1)
or
... boost::shared_ptr spi // initialized to 0
Normally it is a bad form to write spi() since the pointer
could be either (1) a pointer to local variable or (2) a pointer not "fresh"
- shared_ptr's shared_count object exclusively wraps a raw pointer to heap.
So the following code will terribly fail:
int* myIntPtr = new int
c**********e
发帖数: 2007
43
来自主题: Programming版 - C++ Q93 - Q95 (转载)
【 以下文字转载自 JobHunting 讨论区 】
发信人: careerchange (Stupid), 信区: JobHunting
标 题: C++ Q93 - Q95
发信站: BBS 未名空间站 (Fri Oct 14 23:32:57 2011, 美东)
C++ Q93: formal parameter T
What is the purpose of declaring the formal parameter T?
A. T specifies that any data sent to the function template must be of type T
B. T is a place-holder for a C++ data type
C. T can only hold a single data type int
D. T can hold any language data type
C++ Q94: Pointer
Multiple choices: Identify the true statements about the use of... 阅读全帖
r***h
发帖数: 70
44
来自主题: Programming版 - 菜鸟问个C++问题
在看Programming interview exposed
不太明白里面讲link list插入新head的程序的例子.给出2个例子,书上说第一个是错的
,第二个才对.不明白为什么必须用**head而不是*head,难道head本身做为pointer pass
给函数不改变指针的内容吗? 请帮忙讲解一下,谢谢!
For example, the following code is incorrect because it fails to update the
head pointer in the calling function:
int BadInsert(element *head)
{
element *newElem;
newElem = (element *) malloc(sizeof(element));
if (!newElem) return 0;
newElem->next = head;
head = newElem;
return 1;
}
The correct way to update the head pointer in C is to pas... 阅读全帖
k**********g
发帖数: 989
45
Try to write code that will eliminate or avoid some of the bugs in the first
place.
For example, if the argument is required (in this case), don't pass in a
pointer. Use a C++ reference.
void GetNames ( set < string > & names)
{
names.clear();
for (...)
{
names.insert(...);
}
}
If use of pointer argument is necessary, then it is necessary to perform
null pointer check in most cases.
The reason is that, in other languages (Java, C#, anything else), a null
pointer will be c... 阅读全帖

发帖数: 1
46
罪魁祸首找到了:obj := *(*uintptr)(unsafe.Pointer(b + i))
// scanobject scans the object starting at b, adding pointers to gcw.
// b must point to the beginning of a heap object or an oblet.
// scanobject consults the GC bitmap for the pointer mask and the
// spans for the size of the object.
//
//go:nowritebarrier
func scanobject(b uintptr, gcw *gcWork) {
// Note that arena_used may change concurrently during
// scanobject and hence scanobject may encounter a pointer to
// a new... 阅读全帖

发帖数: 1
47
罪魁祸首找到了:obj := *(*uintptr)(unsafe.Pointer(b + i))
// scanobject scans the object starting at b, adding pointers to gcw.
// b must point to the beginning of a heap object or an oblet.
// scanobject consults the GC bitmap for the pointer mask and the
// spans for the size of the object.
//
//go:nowritebarrier
func scanobject(b uintptr, gcw *gcWork) {
// Note that arena_used may change concurrently during
// scanobject and hence scanobject may encounter a pointer to
// a new... 阅读全帖
k*******d
发帖数: 1340
48
来自主题: Quant版 - 问个C++的问题
用vector基本是可以代替array的,因为它也是连续存储的,用的时候小心些基本不会
影响效率,而且它也兼容那些需要指针作为parameter的函数,和老代码可以兼容
不用pointer基本不可能,不用pointer的话怎么实现polymorphism, 虽然reference也
可以,但是限制多,实现多态还是用指针方便,当然,为了安全起见,可以用smart
pointer。
C程序员习惯用pointer,面试题因为都是小规模程序,用指针常常可以更快更简练地解
决问题,所以面试用pointer多,从design角度来看,还是少用raw pointer为好
y**i
发帖数: 1112
49
来自主题: JobHunting版 - 一道老题
有几点不是很明白

the
tha
pointer
第一次循环的时候并不知道vector应该开多大,总不能动态增加吧?那不是还需要一次
循环?
还有这个vector应该顺序存储pointer pairs么?那么第二次循环的时候寻找random
pointer的时候难道要再遍历寻找这个指针在vector里的位置?除非用hash table存储
pointer pairs?那空间应该需求很大了
no
pointers
u
secon
首页 上页 1 2 3 4 5 6 7 8 9 10 下页 末页 (共10页)