了解指针中的*运算符. [英] Understanding * operator in pointers.

查看:84
本文介绍了了解指针中的*运算符.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好,
我不习惯C编程,所以我想了解*运算符在C指针中的用法.我尝试用google搜索它,但是没有什么令人信服的.(一个例子将是非常好的)
我想知道以下指示或功能:-
1. int * i;
2.结构My_DataBase * My_Name; (My_DataBase之前定义为结构)
3. int * i;
4. j = *(int *)k; (j和k定义为整数).
5.结构My_DataBase * My_Name1 =(My_DataBase *)(j +(k * l));

请帮忙,让我知道您是否有任何

Hello,
I am not used to C programming so i would like to understand the useage of * operator in C pointers.I tried to google it but nothing is quite convincing.(An example will be very good)
I would like to know What the following indicate or function as:-
1. int *i;
2. Struct My_DataBase *My_Name; (My_DataBase is defined earlier as a struct)
3. int* i;
4. j = *(int *)k; (j and k are defined as integers).
5. Struct My_DataBase *My_Name1 = (My_DataBase *) (j + (k * l));

Kindly help and let me know if you have any

推荐答案

(1)将i声明为指向int的指针.
(2)将My_Name声明为指向My_Database struct的指针. (3)与(1)的含义相同.
(4)将k解释为指向int的指针(即假设k是地址),将j设置为所指向的int值. (即获取地址为k的int值).
(5)将表达式(j+(k*l))解释为指向struct My_DataBase的指针,设置My_Name1指向相同的位置.

我猜(2),(5)应该写成:
(1) declares i as a pointer to an int.
(2) declares My_Name as a pointer to a My_Database struct.
(3) has the same meaning of (1).
(4) interpreting k as pointer to int (i.e. assuming that k is an address) set j to the int value pointed.
(i.e. get the int value having address k).
(5) interpreting the expression (j+(k*l)) as a pointer to a struct My_DataBase, set My_Name1 pointing to the same location.

I guess (2),(5) should be written:
2. struct My_DataBase *My_Name;
5. struct My_DataBase *My_Name1 = (struct My_DataBase *) (j + (k * l));


:)


请注意 C C ++ 之间的细微差别:

Be careful about the little differences between C and C++:


    允许使用 C ++ 中的
  1. 编写int* p;int *p;来声明p作为指向整数的指针.在 C 中,您应该在 C 中编写int *p;
  2. ,以声明struct类型的变量,您应始终使用以下语法:

  1. in C++ is admitted to write int* p; and int *p; to declare p as a pointer to integer. In C you should write int *p;
  2. in C to declare a variable of a struct type you should always use the following syntax:
struct MyStruct
{
   ...
};

struct MyStruct a;
struct MyStruct *b;


C ++ 中,可以在声明变量时省略struct关键字:


In C++ you can omit the struct keyword when declaring variables:

struct MyStruct
{
   ...
};

MyStruct a;
MyStruct *b;


这篇关于了解指针中的*运算符.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆