C语言读程序的5道题,有答案,泪求详细的解析啊

C语言读程序的5道题,有答案,泪求详细的解析啊,第1张

因为"=="是判断等号两边的值是否相等的语句。

c语言中的“=”是赋值,“==”才是判断。

等号左边是x,它的值为3,右边是y+z,因为"+"的运算优先级大于"=="所以先执行y+z,得到表达式的值为1+0=1.

所以if(x==y+z)等价于判断 if(3==1),"3==1"的返回值自然是false

于是不执行if()语句下的语句,而是执行else中的printf("+++")

所以最后的输出是 +++

啊,是五道题啊...不是第五题...

没看清楚,不好意思。

等下补答

1. 前缀"--"和后缀"--"的区别:前缀返回的是值改变之后的值,后缀返回的是改变之前的值。

所以输出的一个是后缀的10,一个是前缀的9.

当然如果你再printf("%d,%d",x,y)就都输出9了。

2. 因为x,y,z都是整型变量,所以x/y的返回值是整除的值,也就是商。

10/3=3余1,而%相当于mod,也就是10对3取模。取模运算只能对整数进行。

在两个数都是正整数的时候就等于除法的余数,也就是1。

z=(x/y)是赋值语句返回的值就是改变后的z。

3. 可以看到,它printf的是两个表达式的值。而且是两个逻辑表达式。

第一个是(a+b>c &&b==c) “&&”表示且,也就是当两个都为真的时候返回true,任意一个为假,返回false,可以看到a+b>c是true,而b==c是false,所以返回值是false,因为是以整数形式输出,那么就是true=1,false=0.

第二个式子是c>b>a,c语言中没有连比,这个式子会从左算到右。即(c>b)>a。

其中c>b是true,因为要和a这个整型变量比,所以会强制转int变成1,然后1>a返回值就是false了。

4. 也是前置和后置的问题。m=++i 返回的是i=i+1之后的值。也就是6,n=j--返回的是变化之前的值就是12.

意思是删除字符串str1的最后一个字符。 比如:

char str1[]="abc"

则strlen(str1)等于3,strlen(str1)-1等于2。str1[strlen(str1)-1]='\0'即str1[2]='\0'字符串str1变成了"ab",puts(str1)或printf("%s",str1)将输出"ab"。strlen(str1)等于2。

PROCESS BEFORE OUTPUT.

MODULE STATUS_0500.

*

PROCESS AFTER INPUT.

MODULE USER_COMMAND_0500.

*&---------------------------------------------------------------------*

*&Report Z_TEST12

*&

*&---------------------------------------------------------------------*

*&

*&

*&---------------------------------------------------------------------*

REPORT Z_TEST12.

*功能码返回值

DATA:OK_CODE TYPE SY-UCOMM,

SAVE_OK LIKE OK_CODE.

*定制对象

DATA:WA_CONTAINER TYPE SCRFNAME VALUE 'TREE1',

WA_CUSTOM_CONTAINER TYPE REF TO

CL_GUI_CUSTOM_CONTAINER,

WA_TREE TYPE REF TO CL_GUI_SIMPLE_TREE.

*NODE节点

DATA:NODE_TABLE LIKE TABLE OF MTREESNODE,

*节点

NODE1 TYPE MTREESNODE.

*定义内表,变量需要传递,不加HEADER LINE

DATA:WA_SPFLI TYPE TABLE OF SPFLI."WITH HEADER LINE

*当双击时取得节点的KEY值与节点文本值变量

DATA:NODEKEY(200) VALUE 'NONE',NODETEXT(200) VALUE 'NONE'.

*定义对象,定义对象的双击方法,用于将该对象双击方法分*

*配到树双击事件

CLASS LCL_APPLICATION DEFINITION DEFERRED.

*----------------------------------------------------------------------*

* CLASS LCL_APPLICATION DEFINITION

*----------------------------------------------------------------------*

*

*----------------------------------------------------------------------*

CLASS LCL_APPLICATION DEFINITION.

PUBLIC SECTION.

*自定义双击方法,参数为节点关键字

METHODS HANDLE_NODE_DOUBLE_CLICK

FOR EVENT NODE_DOUBLE_CLICK

OF CL_GUI_SIMPLE_TREE

IMPORTING NODE_KEY.

ENDCLASS."LCL_APPLICATION DEFINITION

*&---------------------------------*

*对象方法实现

*&---------------------------------*

CLASS LCL_APPLICATION IMPLEMENTATION.

METHOD HANDLE_NODE_DOUBLE_CLICK.

*MESSAGE I208(00) WITH ’double’.

*取得KEY值,在窗口显示

NODEKEY = NODE_KEY.

*从节点内表中按关键字读取单个节点

READ TABLE NODE_TABLE

WITH KEY NODE_KEY = NODE_KEY

INTO NODE1.

*将节点文本在窗口显示

NODETEXT = NODE1-TEXT.

ENDMETHOD."HANDLE_NODE_DOUBLE_CLICK

ENDCLASS."LCL_APPLICATION IMPLEMENTATION

*定义自定义实例

DATA:G_APPLICATION TYPE REF TO LCL_APPLICATION.

START-OF-SELECTION.

*创建自定义对象

CREATE OBJECT G_APPLICATION.

*直接调用窗口,在窗口PBO分配双击对象

call SCREEN 0500.

*----------------------------------------------------------------------*

* MODULE USER_COMMAND_0500 INPUT

*----------------------------------------------------------------------*

*

*----------------------------------------------------------------------*

MODULE USER_COMMAND_0500 INPUT.

SAVE_OK = OK_CODE.

CLEAR OK_CODE.

CASE SAVE_OK.

WHEN 'EXIT'.

LEAVE PROGRAM.

WHEN 'BACK'.

LEAVE TO SCREEN 0.

ENDCASE.

ENDMODULE."USER_COMMAND_0500 INPUT

*----------------------------------------------------------------------*

* MODULE STATUS_0500 OUTPUT

*----------------------------------------------------------------------*

*

*----------------------------------------------------------------------*

MODULE STATUS_0500 OUTPUT.

SET PF-STATUS '500'.

IF WA_CUSTOM_CONTAINER IS INITIAL.

PERFORM CREATE_TREE.

ENDIF.

ENDMODULE."STATUS_0500 OUTPUT

*&--------------------------------*

*& 创建树及子节点

*&--------------------------------*

FORM CREATE_TREE.

*事件内表及单个事件对象

DATA:EVENTS TYPE CNTL_SIMPLE_EVENTS,

EVENT1 TYPE CNTL_SIMPLE_EVENT.

*建立定制对象

CREATE OBJECT WA_CUSTOM_CONTAINER

EXPORTING

CONTAINER_NAME = WA_CONTAINER.

*建立树对象

CREATE OBJECT WA_TREE

EXPORTING

*LIFETIME =

PARENT = WA_CUSTOM_CONTAINER

*SHELLSTYLE =

NODE_SELECTION_MODE = CL_GUI_SIMPLE_TREE=>NODE_SEL_MODE_SINGLE .

*HIDE_selectION =

*NAME=

*EXCEPTIONS

*LIFETIME_ERROR = 1

*CNTL_SYSTEM_ERROR = 2

*CREATE_ERROR = 3

*FAILED = 4

*ILLEGAL_NODE_selectION_MODE = 5

*OTHERS = 6.

IF SY-SUBRC <>0 .

*MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO

*WITH SY-MSGGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.

ENDIF.

*开始建立树结构

CLEAR NODE1.

*节点关键字

NODE1-NODE_KEY = '国家'.

*第一层

CLEAR NODE1-RELATKEY.

CLEAR NODE1-RELATSHIP.

NODE1-HIDDEN = ''.

NODE1-DISABLED = ''.

NODE1-ISFOLDER = 'X'.

*不带ICON

CLEAR NODE1-N_IMAGE.

CLEAR NODE1-EXP_IMAGE.

CLEAR NODE1-EXPANDER.

*节点文本

NODE1-TEXT = '中国'.

*添加到节点表

APPEND NODE1 TO NODE_TABLE.

*二层节点

CLEAR NODE1.

NODE1-NODE_KEY = '成都'.

*上层关系

NODE1-RELATKEY = '国家'.

NODE1-RELATSHIP = CL_GUI_SIMPLE_TREE=>RELAT_LAST_CHILD

.

NODE1-HIDDEN = ''.

NODE1-DISABLED = ''.

NODE1-ISFOLDER = 'X'.

CLEAR NODE1-N_IMAGE.

CLEAR NODE1-N_IMAGE.

CLEAR NODE1-EXP_IMAGE.

CLEAR NODE1-EXPANDER.

NODE1-TEXT = '成都'.

APPEND NODE1 TO NODE_TABLE.

CLEAR NODE1.

NODE1-NODE_KEY = '深圳'.

*上层关系

NODE1-RELATKEY = '国家'.

NODE1-RELATSHIP = CL_GUI_SIMPLE_TREE=>RELAT_LAST_CHILD

.

NODE1-HIDDEN = ''.

NODE1-DISABLED = ''.

NODE1-ISFOLDER = 'X'.

CLEAR NODE1-N_IMAGE.

CLEAR NODE1-N_IMAGE.

CLEAR NODE1-EXP_IMAGE.

CLEAR NODE1-EXPANDER.

NODE1-TEXT = '深圳'.

APPEND NODE1 TO NODE_TABLE.

CLEAR NODE1.

NODE1-NODE_KEY = '武侯区'.

*上层关系

NODE1-RELATKEY = '成都'.

NODE1-RELATSHIP = CL_GUI_SIMPLE_TREE=>RELAT_LAST_CHILD

.

NODE1-HIDDEN = ''.

NODE1-DISABLED = ''.

NODE1-ISFOLDER = ''.

CLEAR NODE1-N_IMAGE.

CLEAR NODE1-EXP_IMAGE.

CLEAR NODE1-EXPANDER.

NODE1-TEXT = '武侯区'.

APPEND NODE1 TO NODE_TABLE.

CLEAR NODE1.

NODE1-NODE_KEY = '金牛区'.

*上层关系

NODE1-RELATKEY = '成都'.

NODE1-RELATSHIP = CL_GUI_SIMPLE_TREE=>RELAT_LAST_CHILD

.

NODE1-HIDDEN = ''.

NODE1-DISABLED = ''.

NODE1-ISFOLDER = ''.

CLEAR NODE1-N_IMAGE.

CLEAR NODE1-N_IMAGE.

CLEAR NODE1-EXP_IMAGE.

CLEAR NODE1-EXPANDER.

NODE1-TEXT = '金牛区'.

APPEND NODE1 TO NODE_TABLE.

CLEAR NODE1.

NODE1-NODE_KEY = '福田区'.

*上层关系

NODE1-RELATKEY = '深圳'.

NODE1-RELATSHIP = CL_GUI_SIMPLE_TREE=>RELAT_LAST_CHILD

.

NODE1-HIDDEN = ''.

NODE1-DISABLED = ''.

NODE1-ISFOLDER = ''.

CLEAR NODE1-N_IMAGE.

CLEAR NODE1-N_IMAGE.

CLEAR NODE1-EXP_IMAGE.

CLEAR NODE1-EXPANDER.

NODE1-TEXT = '福田区'.

APPEND NODE1 TO NODE_TABLE.

CLEAR NODE1.

NODE1-NODE_KEY = '南山区'.

*上层关系

NODE1-RELATKEY = '深圳'.

NODE1-RELATSHIP = CL_GUI_SIMPLE_TREE=>RELAT_LAST_CHILD

.

NODE1-HIDDEN = ''.

NODE1-DISABLED = ''.

NODE1-ISFOLDER = ''.

CLEAR NODE1-N_IMAGE.

CLEAR NODE1-N_IMAGE.

CLEAR NODE1-EXP_IMAGE.

CLEAR NODE1-EXPANDER.

NODE1-TEXT = '南山区'.

APPEND NODE1 TO NODE_TABLE.

*按照节点内表添加节点

CALL METHOD WA_TREE->ADD_NODES

EXPORTING

TABLE_STRUCTURE_NAME = 'MTREESNODE'

NODE_TABLE = NODE_TABLE.

*EXCEPTIONS

*ERROR)IN_NODE_TABLE = 1

*FAILED = 2

*DP_ERROR = 3

*TABLE_STRUCTURE_NAME_NOT_FOUND = 4

*OTHERS = 5.

IF SY-SUBRC <>0.

*MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO

*WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.

ENDIF.

*定义双击事件

EVENT1-EVENTID =

CL_GUI_SIMPLE_TREE=>EVENTID_NODE_DOUBLE_CLICK.

EVENT1-APPL_EVENT = 'X'.

APPEND EVENT1 TO EVENTS.

*添加事件内表

CALL METHOD WA_TREE->SET_REGISTERED_EVENTS

EXPORTING

EVENTS = EVENTS.

* EXCEPTIONS

* CNTL_ERROR = 1

* CNTL_SYSTEM_ERROR = 2

* ILLEAGL_EVENT_COMBINATION = 3

* OTHERS = 4

IF SY-SUBRC <>0.

*MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO

* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.

ENDIF.

*将已定义的双击事件分配到树对象

SET HANDLER G_APPLICATION->HANDLE_NODE_DOUBLE_CLICK

FOR WA_TREE.

ENDFORM. "create_tree


欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/yw/11572015.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-05-17
下一篇 2023-05-17

发表评论

登录后才能评论

评论列表(0条)

保存