一、比较语句大部分和其他的语言一样,这里注意、条件语句如下几种形式ifif ..else.. endif..elsif..else..endunless(if not)case..whenx=1if x==1 puts 1elsif x==2 puts 2else puts 3...
分类:
其他好文 时间:
2014-06-28 10:13:10
阅读次数:
265
模块模块同类一样,也有 class method 和 instance method。module 没有new不能生成实例对象其中 class method 在模块中称为模块方法,是可以直接调用的。module Foo
def self.hello
puts 'hello world!'
end
def Foo.dear #module全局作用域内的self还是没有变,就是...
分类:
其他好文 时间:
2014-06-26 14:19:28
阅读次数:
163
C有三个用于输出字符串的标准库函数puts()、fputs()和printf()。
1、puts()函数只需要给出字符串参数的地址。
#include
int puts(const char *s);
示例:
#include
#define DEF "I am libing"
int
main(int argc, char **argv)
{
char str1[30] =...
分类:
编程语言 时间:
2014-06-24 22:04:37
阅读次数:
368
关于数组Ruby数组中的数据类型可以不相同并且长度也是可变的。(好聪明啊感觉用的久了就会变笨了,除非你本来就是老手)比如下面的例子Myarray=[1,2,“ruby”]Ruby也支持那种-1的表示,比如arry=[1,2,"ruby"]puts arry[-4]puts arry[-3]puts ...
分类:
其他好文 时间:
2014-06-21 08:44:56
阅读次数:
617
1、代码块代码块是用大括号或者do...end括起来的一系列代码。{ #this is a block}do #this is a blockend[1,2,3,4,5].each {|i| puts i}[1,2,3,4,5].each do |i|puts iend这2中写法效果是一样的,用{}可能更像C的风格2、作用域Ruby程序只会在3个地方关闭前一个作用域,同时打开一个新的作用域: 类定...
分类:
其他好文 时间:
2014-06-14 17:45:04
阅读次数:
150
1、单行注释用:#2、多行注释用:=begin ...
=end3、语句分隔用;号4、空格在省略()的地方代替()号5、方法定义用:def
undef6、检查类型用:defined?7、变量:全局变量用$,实例变量用@(后面不能直接跟数字),类变量用@@8、输出:puts(每一个变量输出都加一个换行...
分类:
其他好文 时间:
2014-06-13 00:47:40
阅读次数:
301
下面的代码片段输出是什么?为什么?
char *ptr;
if((ptr = (char *)malloc(0))==NULL)
puts("Got a null pointer");
else
puts("Got a valid pointer");
解析:......故意把0值传给了函数malloc,得到了一个合法的指针,这就是上面的代码,该代码的输出是"Got ...
分类:
其他好文 时间:
2014-06-08 17:11:28
阅读次数:
285
irb(main):001:0> puts "a", "\nb" a b => nil
irb(main):002:0> p "a", "\nb" "a" "\nb" => nil irb(main):003:0> print
"a", "\nb" a b=> nil puts会识别双引号""内.....
分类:
其他好文 时间:
2014-05-26 16:15:36
阅读次数:
249
#建立一个222.rb文件并且输入字符file =
File.open("222.rb","w+")file.puts
"123\nwadwa\n12124124\ndwdw"file.close#输出222.rb的内容File.open("222.rb","r+") do
|file|while ...
分类:
其他好文 时间:
2014-05-26 16:07:50
阅读次数:
293
hdu1021int main(n){ for(;~scanf("%d",&n);)
if(n-2)%4==0) puts("yes"); else puts("no"); return 0;}View Codenefu115 方法跟上...
分类:
其他好文 时间:
2014-05-23 05:13:13
阅读次数:
236