今天发现VS2010不支持round
C++项目中的功能.有关该功能的信息已在此处找到.还注意到也没有trunc
功能.
所以尝试了一些东西并注意到一些可能有助于这种情况的行为.
float a = 2.999;
int b = (int)a; //gives 2
Run Code Online (Sandbox Code Playgroud)
float a = -2.999;
int b = (int)a; //gives -2
Run Code Online (Sandbox Code Playgroud)
这可以作为截断,所以我可以使用它,但是我不想使用导致未定义行为的代码.所以想问一下这是定义的还是未定义的行为.
编辑:因为我正在使用VS2008,所以我不会问C++ 11.
我确信这很简单,但如果不打破我的页面,我就无法得到这个:
<?php
$values = get_field('testimonial_text');
if($values) {
echo '
<div class="testimonial entry-content">
<h2><?php the_field('testimonial_title'); ?></h2>
<?php the_field('testimonial_text'); ?>
</div>';
} else {
echo '';
}
?>
Run Code Online (Sandbox Code Playgroud)
有人能告诉我我做错了什么,为什么我做的不行.
最终,库函数将返回一个值.谁捕获了此返回值?
例如,请考虑以下代码.
#include<stdio.h>
main()
{
printf("Waiting for a character to be pressed from the keyboard to exit.\n");
getch();
return 0;
}
Run Code Online (Sandbox Code Playgroud)
getch()
返回一个值.谁捕获了这个价值?
给我一般意义上的答案,而不是上述程序的具体内容.
我对表达感到困惑*d++=*s++
.如何承担它.
int main()
{
char s[20]="hello,world";
char d[20];
char *src=s;
char *des=d;
while(*src) *des++=*src++;
return 0;
}
Run Code Online (Sandbox Code Playgroud) 我有一个未初始化的int指针.打印时,此值始终显示为0.
但是当检查NULL时,它不会通过条件.
有趣的是,这个野生指针在没有抛出Segmentation Fault的情况下获取价值.
任何解释??
代码如下:
int main (){
int *p1;
int *p2;
int var=90;
printf("p1 = %x\n", p1);
printf("p2 = %x\n", p2);
p1 = &var;
if(p2==NULL)
{return 0;}
*p2 = *p1;
printf("*p2 = %x\n", *p2);
}
Run Code Online (Sandbox Code Playgroud)
输出看起来像这样..
# gcc -std=c99 -o main *.c
# main
p1 = 0
p2 = 0
*p2 = 90
Run Code Online (Sandbox Code Playgroud) 我发现C99添加_Complex
了支持复杂算术.但是,我想知道为什么C99为这样一个与字段相关的功能添加新关键字(仅对科学计算有用).通过标准库支持复杂类型不是更好吗?
我写了这个程序
#include<stdio.h>
struct student
{
char name[22];
char rollno[10];
unsigned long long int phno;
};
int main()
{
int i,j;
char c[1];
struct student cse[10],*p;
p=cse;
for(i=0;i<3;i++)
{
printf("enter student name\n");
gets(cse[i].name);
printf("enter student roll number \n");
gets(cse[i].rollno);
printf("enter student phone number \n");
scanf("%llu",&cse[i].phno);
gets(c); //to catch the '\n' left unprocessed by scanf
}
for(i=0;i<3;i++);
printf("the following is the information about CSE B student\n");
printf("%-6s%-24s%-14s%-14s \n","S.no","student Name","Roll no","phone no.");
for(i=0;i<3;i++)
{
printf("%-6d%-24s%-20s%-14llu \n",i+1,(*p).name,(*p).rollno,(*p).phno);
++p;
}
return 0;
}
Run Code Online (Sandbox Code Playgroud)
输出是
the …
Run Code Online (Sandbox Code Playgroud) 我需要我的程序显示有关文件的信息.所以这是我的代码
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>
int main(int argc, char *argv[]){
struct stat fileStat;
if (argc != 2) {
fprintf(stderr, "Usage: %s <pathname>\n", argv[0]);
exit(0);
}
if (stat(argv[1], &fileStat) == -1) {
exit(1);
}
printf("ID ", fileStat.st_uid);
printf("Dydis: \t\t%d bytes\n" + fileStat.st_size);
}
Run Code Online (Sandbox Code Playgroud)
但是我得到了这个错误
Segmentation Fault (core dumped)
Run Code Online (Sandbox Code Playgroud)
有什么想法有什么不对吗?
我有以下代码
char * find(struct node *r,char *str)
{
r=head;
if(r==NULL)
{
return NULL;
}
while(r!=NULL)
{
if((strcmp(str,r->name) == 0))
{
printf("found %s\n",r->name);
char *p = malloc(256);
strcpy(p,(const char *)r->name);
return p;
}
r=r->next;
}
return NULL;
}
Run Code Online (Sandbox Code Playgroud)
并在main
:
void main ()
{
......
......
char *ret;
ret = find(n,"someone");
printf("%s\n",ret);
.......
}
Run Code Online (Sandbox Code Playgroud)
使用上面的代码,我总是有分段错误.但是当我取消ret
变量时.有用.
void main ()
{
......
......
printf("%s\n",find(n,"someone"));
.......
}
Run Code Online (Sandbox Code Playgroud)