新手求解!

奋斗的勇介 2012-10-25 02:47:14
初学c++,看到有时候有的代码中,出现char* ,这个char*是什么意思?为什么有个*呢??
还有有时候我看到有的代码有四个点,例如::,这四个点是什么意思,作用是??
谢谢解答!!困扰了很久了!!
...全文
242 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
奋斗的勇介 2012-11-08
  • 打赏
  • 举报
回复
谢谢你们!!
  • 打赏
  • 举报
回复
char * 代表字符指针,通常也用作表示字符串 函数返回一个字符串多半用char * ;
::是作用域标示符,如A::a();就表示函数a()是属于类A的,A::b;则表示变量b属于类A,可以简单地理解为哪个类的成员。
ouuyang 2012-10-25
  • 打赏
  • 举报
回复
char* 是指向char类型的指针,代表存储的地址
至于 :: 可以参考以下用法

class A
{
public static fn();
}

你可以这样调用
A::fn();

A 可看作一个作用域,fn是A中的一个方法,::这个就是域操作符
赵4老师 2012-10-25
  • 打赏
  • 举报
回复
查MSDN是Windows程序员必须掌握的技能之一。
mk:@MSITStore:C:\MSDN98\98VS\2052\vclang.chm::/html/_clang_pointer_declarations.htm
Pointer Declarations
A “pointer declaration” names a pointer variable and specifies the type of the object to which the variable points. A variable declared as a pointer holds a memory address.

Syntax

declarator :

pointer opt direct-declarator

direct-declarator :

identifier
( declarator )
direct-declarator [ constant-expression opt ]
direct-declarator ( parameter-type-list )
direct-declarator ( identifier-list opt )

pointer :

* type-qualifier-list opt
* type-qualifier-list opt pointer

type-qualifier-list :

type-qualifier
type-qualifier-list type-qualifier

The type-specifier gives the type of the object, which can be any basic, structure, or union type. Pointer variables can also point to functions, arrays, and other pointers. (For information on declaring and interpreting more complex pointer types, refer to Interpreting More Complex Declarators.)

By making the type-specifier void, you can delay specification of the type to which the pointer refers. Such an item is referred to as a “pointer to void” and is written as void *. A variable declared as a pointer to void can be used to point to an object of any type. However, to perform most operations on the pointer or on the object to which it points, the type to which it points must be explicitly specified for each operation. (Variables of type char * and type void * are assignment-compatible without a type cast.) Such conversion can be accomplished with a type cast (see Type-Cast Conversions for more information).

The type-qualifier can be either const or volatile, or both. These specify, respectively, that the pointer cannot be modified by the program itself (const), or that the pointer can legitimately be modified by some process beyond the control of the program (volatile). (See Type Qualifiers for more information on const and volatile.)

The declarator names the variable and can include a type modifier. For example, if declarator represents an array, the type of the pointer is modified to be a pointer to an array.

You can declare a pointer to a structure, union, or enumeration type before you define the structure, union, or enumeration type. You declare the pointer by using the structure or union tag as shown in the examples below. Such declarations are allowed because the compiler does not need to know the size of the structure or union to allocate space for the pointer variable.

Examples

The following examples illustrate pointer declarations.

char *message; /* Declares a pointer variable named message */

The message pointer points to a variable with char type.

int *pointers[10]; /* Declares an array of pointers */

The pointers array has 10 elements; each element is a pointer to a variable with int type.

int (*pointer)[10]; /* Declares a pointer to an array of 10 elements */

The pointer variable points to an array with 10 elements. Each element in this array has int type.

int const *x; /* Declares a pointer variable, x,
to a constant value */

The pointer x can be modified to point to a different int value, but the value to which it points cannot be modified.

const int some_object = 5 ;
int other_object = 37;
int *const y = &fixed_object;
const volatile *const z = &some_object;
int *const volatile w = &some_object;

The variable y in these declarations is declared as a constant pointer to an int value. The value it points to can be modified, but the pointer itself must always point to the same location: the address of fixed_object. Similarly, z is a constant pointer, but it is also declared to point to an int whose value cannot be modified by the program. The additional specifier volatile indicates that although the value of the const int pointed to by z cannot be modified by the program, it could legitimately be modified by a process running concurrently with the program. The declaration of w specifies that the program cannot change the value pointed to and that the program cannot modify the pointer.

struct list *next, *previous; /* Uses the tag for list */

This example declares two pointer variables, next and previous, that point to the structure type list. This declaration can appear before the definition of the list structure type (see the next example), as long as the list type definition has the same visibility as the declaration.

struct list
{
char *token;
int count;
struct list *next;
} line;

The variable line has the structure type named list. The list structure type has three members: the first member is a pointer to a char value, the second is an int value, and the third is a pointer to another list structure.

struct id
{
unsigned int id_no;
struct name *pname;
} record;

The variable record has the structure type id. Note that pname is declared as a pointer to another structure type named name. This declaration can appear before the name type is defined.

mk:@MSITStore:C:\MSDN98\98VS\2052\vclang.chm::/html/_pluslang_global_names.htm
Global Names
A name of an object, function, or enumerator is global if it is introduced outside any function or class or prefixed by the global unary scope operator (::), and if it is not used in conjunction with any of these binary operators:

Scope-resolution (::)


Member-selection for objects and references (.)


Member-selection for pointers (–>)

英语也是一门计算机语言的说。
hust_terry 2012-10-25
  • 打赏
  • 举报
回复
初学了多久?看过书没?
cshuang01 2012-10-25
  • 打赏
  • 举报
回复
没必要浪费分,概念性的东西,看看书,练习练习就好了
RedFishing 2012-10-25
  • 打赏
  • 举报
回复
char* 指的是字符型的指针类型
::指的是作用域符
这些东西在论坛啊。。度娘上面应该都可以搜得到的- -
yisikaipu 2012-10-25
  • 打赏
  • 举报
回复
指针
作用域符

64,649

社区成员

发帖
与我相关
我的任务
社区描述
C++ 语言相关问题讨论,技术干货分享,前沿动态等
c++ 技术论坛(原bbs)
社区管理员
  • C++ 语言社区
  • encoderlee
  • paschen
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
  1. 请不要发布与C++技术无关的贴子
  2. 请不要发布与技术无关的招聘、广告的帖子
  3. 请尽可能的描述清楚你的问题,如果涉及到代码请尽可能的格式化一下

试试用AI创作助手写篇文章吧