C中的问题 [英] problem in C

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

问题描述

第一个问题

程式:

1st problem

Program :

 #include<stdio.h>
 #include<conio.h>
 
void main(){
 extern int a;
 printf("%d",a);
  }
int a=20;</conio.h></stdio.h>




第一次运行该程序时,痛风输出为20
但是之后,每当我尝试运行相同的程序时,我都会收到错误消息"0x1f处的非法变量"

且输出应为20(根据一本书的解决方案手册)


第二个问题

程序




when at first time i run this program , i gout output as 20
but after that whenever i tried to run this same program i got an error "Illegal variable at 0x1f"

and output should be 20 (according to solution manual of a book)


2nd problem

Program

 #include<stdio.h>
 #include<conio.h>

int main(){clrscr();
 ichar str[] = "Part time musicians ar semiconductors";
int a = 5;
printf(a>10?"%50s":"%s",str);
getch();
  }</conio.h></stdio.h>



在此程序中,我不了解%50s"的含义.
请向我解释%50s"的含义.


第三个问题

程式:



here in this program i dont understand the significance of "%50s".
please explain me what "%50s" mean.


3rd Problem

Program :

main(){
      char far *s1,*s2;
      printf("%d%d",sizeof(s1),sizeof(s2));
}



该程序输出:4 2
但是我不明白它是怎么来的,因为这里没有定义任何值.



this program gives output : 4 2
but i dont understan how it comes as no value is defined here.

推荐答案

问题1-您的应用每次运行时都应提供相同的输出.您确定代码没有更改吗?

问题2-这是一种格式说明符,在这种情况下,它指定了要打印的最小字符数

问题3-sizeof告诉您值包含多少字节.因为您的char *尚未初始化,所以它们指向随机数据.不确定为什么值会不同,我不确定远"是什么,或者它是否仅适用于第一个.

其他一些要点:

1-您的书听起来不像它那么好,特别是如果它要求您使用格式说明符而不对其进行解释的话

2-如果您尝试过,Google会回答所有这些问题

3-C是较旧的语言,不是OO,主要用于微控制器等.除非您有特定的原因要学习C,否则,如果您想编写常规的Windows程序,C的使用方法是错误的.
Problem 1 - your app should give the same output every time you run it. Are you SURE there''s no change to your code ?

Problem 2 - That''s a format specifier, in this case, it''s specifying the minimum number of characters to print

Problem 3 - sizeof tells you how many bytes a value contains. Because your char * are not initialised, they point to random data. Not sure why the values differ, I am not sure what ''far'' does or if it just applies to the first one, seems likely.

Some additional points:

1 - your book doesn''t sound like it''s that great, especially if it asked you to use format specifiers without explaining them

2 - google would have answered all of these questions if you tried

3 - C is an older language which is not OO and is mostly used for micro controllers and so on. Unless you have a specific reason for wanting to learn C, if you want to write general windows programs, C is the wrong way to go about it.


#2:%50s意味着编写一个至少包含50个字符的字符串.必要时用空格填充.

#3:sizeof运算符以字节为单位报告其参数的大小,即所打印的内容(假设远近指针)

至于#1,我不知道.重建/重试.它应该起作用.
#2: %50s means writing a string with minimum of 50 chars. Padding with spaces if necessary.

#3: The sizeof operator reports the size in bytes of its argument, and that''s what is printed (assuming far and near pointers)

As for #1, I have no idea. Rebuild / retry. It should work.


我不知道为什么您认为您必须学习"C.C不是面向对象的,并且使用指针使它比现代语言.我会先学习C#,然后如果您出于任何原因需要C ++,请回到C ++.在如今的今天,C对于通用编程基本上是无用的,因为它太钝了,并且由于它不具有伸缩性,不具备现代开发所需的工具而无法在大型项目中使用.一个),并且在任何现代框架中都没有真正的支持.
I have no idea why you think you ''must learn'' C. C is not object oriented, and it''s use of pointers makes it more difficult than modern languages. I would learn C# first, then go back to C++ if you ever need it for any reason. C is basically useless in this day and age for general programming, because it''s too obtuse, and does not lend itself to being used in major projects because it does not scale, does not have the tools needed for modern development ( classes for one ), and there is no real support for it anywhere in any modern framework.


这篇关于C中的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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