#include<stdio.h>
int main()
{
struct s{
int bit_fld:3;
};
s a;
a.bit_fld=0x10;
a.bit_fld =( a.bit_fld | (1<<2));
printf("%x\n",a.bit_fld);
return 0;
}
Run Code Online (Sandbox Code Playgroud)
该计划输出fffffffc.
我试图手动计算输出,我无法获得编译器生成的输出.
bit_fld = 00010000 and (1<<2) = 0100oring两个结果00010100都是0x14十六进制的.为什么我对输出的看法是错误的?帮助我理解我错在哪里.
#include "stdafx.h"
#include<stdio.h>
int aarray[]={1,2,3,4,5,6,7,8};
#define SIZE (sizeof(aarray)/sizeof(int))
int main()
{
printf("%d\n",SIZE);
if(-1<=SIZE)printf("1\n");
else printf("2\n");
return 0;
}
Run Code Online (Sandbox Code Playgroud)
为什么打印2?SIZE是8,大于-1所以它应该打印1.但为什么打印2?请帮我理解.
#include<stdio.h>
#define A(int x) printf("%d\n",x)
#define AS(A) A(20)
typedef struct{
int *m;
int n;
int k;
}st;
//static st sb[10] = {AS(A)}
int main()
{
AS(A);
return 0;
}
Run Code Online (Sandbox Code Playgroud)
我收到如下错误.
Line 14: error: macro parameters must be comma-separated
Run Code Online (Sandbox Code Playgroud)
请帮忙.
我是Objective CI的新手,正在尝试一些示例程序.我无法理解自我和超级方法如何在目标C中工作.在下面的pgm中,CashTransaction.m [super trackSpending:amount]被调用并且在CreditCardTransaction.m中[self] trackspending:amount]被调用.我找不到self和super.super之间的区别用于调用基类重写方法.self用于调用子类重写方法.这就是我的理解.请纠正我,如果我错了.谢谢你.
#import <Foundation/Foundation.h>
#import "BudgetObject.h"
#import "Transaction.h"
#import "CashTransaction.h"
#import "CreditCardTransaction.h"
int main (int argc, const char * argv[]) {
//!---Creating An Object And Allocating It With Values---
Budget* budget = [Budget new];
[budget createBudget:1000.00 withExchangeRate:1.2500];
//!---Declaring And Adding Elements To An Array---
NSMutableArray* transactions = [[NSMutableArray alloc] initWithCapacity:10];
Transaction* aTransaction;
aTransaction = [Transaction new];
[transactions addObject:aTransaction];
//!---Calculating The No Of Elements In An Array---
int k;
k=[transactions count];
NSLog(@"The count value is:%d",k);
//!---Selecting According …Run Code Online (Sandbox Code Playgroud) #include<stdio.h>
#include<string.h>
#include<malloc.h>
char *str_rev(char s[]){
static char *st = NULL;
static char *l;
int i = 0,c = 0;
st = malloc((strlen(s) * sizeof(*s))+1);
*l = st;
if(s == NULL){
return "INVALID PARAMS";
}
for(i=0;s[i]!='\0';i++){
;
}
for(c=i;c >=0;c--){
*l++ = s[c];
}
l = '\0';
return st;
}
int main(){
char a[]="Angus Declan R";
printf("\n %s \n",str_rev(a));
return 0;
}
Run Code Online (Sandbox Code Playgroud)
如何在func str_rev()中释放使用malloc()分配的内存,因为我需要重新调整反向字符串.
#include<stdio.h>
int main(){
int ret = 0;
ret = func(1.0,2.0);
printf("\n ret : %d \n",ret);
return 0;
}
func(int a,int b){
float m = 5.0;
float n = 6.0;
int sum = m + n;
printf("\n sum : %d \n",sum);
return a+b;
}
Run Code Online (Sandbox Code Playgroud)
EDITED
总和:11
ret:-877505847
为什么传递给整数的浮点值抛出一个垃圾值,而浮点值添加并赋值给函数内的整数给出正确的值11?
我正在尝试一个示例程序,它可以计算命令行参数中给出的文件大小.当我在变量中存储文件名时,它会正确地给出大小,但是当从命令行参数获取文件名时不会输出结果.
#! /usr/bin/perl
use File::stat;
while(<>){
if(($_ cmp "\n") == 0){
exit 0;
}
else{
my $file_size = stat($_)->size; # $filesize = s $_;
print $file_size;
}
}
Run Code Online (Sandbox Code Playgroud)
使用文件测试操作符时没有输出-s,使用stat模块时出错:
Unsuccessful stat on filename containing newline at /usr/share/perl/5.10/File/stat.pm line 49, <> line 1.
Can't call method "size" on an undefined value at 2.pl line 17, <> line 1.
Run Code Online (Sandbox Code Playgroud)
1.txt是我给出的文件名作为输入.
#!/bin/bash
for m in `ls f-*`
do
$i = 0
echo "$m"
arr[$i] = $m
$i = $i + 1
done
Run Code Online (Sandbox Code Playgroud)
我想在数组中存储以f-开头的文件名.上面的代码不起作用.
编辑:
#!/bin/bash
i=0
ls f-* | while read m
do
#echo $m
arr[$i]=$m
i=$((i+1))
done
Run Code Online (Sandbox Code Playgroud)
我收到以下错误,
my_script.sh: 7: my_script.sh: arr[0]=f-1: not found
my_script.sh: 7: my_script.sh: arr[1]=f-10: not found
my_script.sh: 7: my_script.sh: arr[2]=f-15: not found
my_script.sh: 7: my_script.sh: arr[3]=f-2: not found
my_script.sh: 7: my_script.sh: arr[4]=f-20: not found
my_script.sh: 7: my_script.sh: arr[5]=f-3: not found
my_script.sh: 7: my_script.sh: arr[6]=f-4: not found …Run Code Online (Sandbox Code Playgroud) #include<stdio.h>
int main(int argc,char* argv[]){
printf("\n argc : %d \n",argc);
return 0;
}
Run Code Online (Sandbox Code Playgroud)
输出:
[root@aman]# ./a.out *
argc : 8
Run Code Online (Sandbox Code Playgroud)
我已经传递了两个参数,因此argc值必须为2,但它显示为8.我想将*存储在一个数组中并比较输入的'*'字符串.
我正在编写一个工具来删除列表中的所有条目.因此我需要从"./a.out*"验证*是否输入.如果输入我需要做与之对应的动作.有没有办法用作./a.out*并取用户输入的*.
PIPES是单向的,可以在通信中同步或异步.
但是如何在一个进程上创建一个双向命名管道,在另一个进程上创建另一个端点,这两个进程共享同一个内存,并且存在于同一操作系统中并异步通信.
有办法吗?
c ×6
bash ×1
bit-fields ×1
kernel ×1
linux ×1
linux-kernel ×1
objective-c ×1
perl ×1
self ×1
shell ×1
super ×1