#include<stdio.h>
int main()
{
unsigned int a=6;
int b=-20;
(a+b>6)?puts(">6"):puts("<=6");
return 0;
}
Run Code Online (Sandbox Code Playgroud)
上面的代码输出>6.但我怀疑了.在执行2的补码之后b=-20将保持负值(-18),因为它是有符号整数.所以它应该输出,<=6但它给出一个输出>6.
#include<stdio.h>
#include<string.h>
int main()
{
unsigned char *s;
unsigned char a[30]="Hello world welcome";
memcpy(s,&a,15);
printf("%s",s);
return 0;
}
Run Code Online (Sandbox Code Playgroud)
这给了我一个分段错误.请帮我修复此错误
我在我的代码中添加了第三方库,并在运行时遇到这样的错误make.请帮我理解这个错误.
(.text+0x9b4): undefined reference to `snd_strerror'
/home/bet/Tent/tun/app/Common/hl/lib/libGHAL.a(gfxhal.o): In function `GFX_create_region':
/home/bet/Tent/tun/app/Common/hl/src/GHAL/gfxhal.c:1141: undefined reference to `my_key_handler'
/home/bet/Tent/tun/app/Common/hal/src/GHAL/gfxhal.c:1141: undefined reference to `create_window'
collect2: ld returned 1 exit status
make[2]: *** [all] Error 1
make[2]: Leaving directory `/home/bet/Tent/tun/app/Common/c_app'
make[1]: *** [ctv_all] Error 2
make[1]: Leaving directory `/home/bet/Tent/tun/app/Common'
Run Code Online (Sandbox Code Playgroud) #include <stdio.h>
int main(){
int a[4];
int b[4],i;
a[0] = 4;
a[1] = 3;
a[2] = 2;
a[3] = 1;
memcpy(&b, &a, sizeof(a));
for (i = 0; i < 4; i++){
printf("b[%d]:%d",i,b[i]);
}
printf("%d",sizeof(b));
}
Run Code Online (Sandbox Code Playgroud)
b[0]:4b[1]:3b[2]:2b[3]:116
Exited: ExitFailure 2
Run Code Online (Sandbox Code Playgroud)
我得到了正确的答案.但是获得Exited:ExitFailure 2的异常.
这种使用memcpy复制数组数据的方法是错误的吗?
#include<stdio.h>
int* a(int* b){
int a = 20;
printf("\n \n");
if(a == 20){
printf("\n return from if a : 0x%x \n",a);
return &a;
}
else{
printf("\n returning from else b : 0x%x\n",b);
return b;
}
}
int main(){
int n = 10;
int *k,*m;
k = &n;
m = a(k);
printf("\n m ; 0x%x m : %d \n",m,*m);
return 0;
}
Run Code Online (Sandbox Code Playgroud)
这里我返回函数返回指针的局部变量.在函数退出期间,所有变量都将从堆栈内存中移出,但该函数如何仍保留地址"a"的值并打印数据?
o/p:
return from if a : 0xbfd8cf14
m ; 0xbfd8cf14 m : 20
Run Code Online (Sandbox Code Playgroud)
地址保留在指针m中,并正确打印该值.我尝试改变不同的不是.
我不知道我需要问哪个标签这个问题.我目前正在研究数字电视广播的ATSC标准.在浏览内容时我有疑虑.在数字电视广播中,单个带宽将包含多个频道(服务).
由广播公司编码和多路复用的数据称为传输流.
传输流由标头和有效负载组成.标题包括音频基本流或视频基本流或数据基本流的PID.该传输流由包含中间件的机顶盒接收,该中间件解析传输流并将数据放入PAT,PMT,EIT,ETT,SDT,NIT,CAT表中.
是否可以使用PSI表而不是ATSC表?
给定如下程序如何识别有符号整数是否将转到-ve或+值.
int main()
{
int a=0xDEADBEEF;
printf("%d",a);
return 0;
}
Run Code Online (Sandbox Code Playgroud)
这个输出在-ve.But有任何简单的方法来快速识别它而无需在visual studio中执行.
#include<stdio.h>
int main(){
int a[5] = {0,1,2,3,4};
int * ptr;
ptr =(int *) &a;
printf("\n&a:%u,&a[0]:%u,ptr:%u\n",&a,&a[0],ptr);
ptr = (int*)(&a+1);
printf("\n&a:%u,&a[0]:%u,ptr:%u\n",&a,&a[0],ptr);
ptr = (int*)(&a);
ptr = (int*)(&a[0]+4);
printf("\n&a:%u,&a[0]:%u,ptr:%u,*ptr:%d\n",&a,&a[0],ptr,*ptr);
return 0;
}
Run Code Online (Sandbox Code Playgroud)
O/P:
&a:3213284540,&a[0]:3213284540,ptr:3213284540
&a:3213284540,&a[0]:3213284540,ptr:3213284560
&a:3213284540,&a[0]:3213284540,ptr:3213284556,*ptr:4
Run Code Online (Sandbox Code Playgroud)
在上面的代码&a和&a[0]给出相同的地址3213284540.但添加的两种情况1给出了不同的地址.
&a[0]+1 => 3213284540 + 4 = 3213284544 [The value stored in this address is '1']
&a+1 => 3213284540 + (5*4) = 3213284560 [Goes Out of bounds of the array]
&a+1 is equivalent to sizeof(array)+1.
Run Code Online (Sandbox Code Playgroud)
但是编译器如何解释这个
&a[0]+1和&a+1 …
#include<unistd.h>
#include<stdio.h>
void *my_malloc(size_t size){
void *p;
void *q;
p = sbrk(0);
/* If sbrk fails, we return NULL */
q = sbrk(size);
if(q == (void *)-1){
return NULL;
}
printf("\n size : %d p : 0x%x q : 0x%x \n",size,p,q);
return p;
}
int main(){
int *p;
p = my_malloc(5);
printf("\n p : 0x%x \n",p);
}
Run Code Online (Sandbox Code Playgroud)
brk(2) place the break at the given adress addr and return 0 if successful, -1 otherwise. The global errno symbol indicate the nature …
#include<stdio.h>
void int_copy(int* ptrA,int* ptrB,int nbr){
//int* temp = ptrB;
while(nbr != 0){
*ptrB++ = *ptrA++;
nbr--;
}
*ptrB = -1;
//ptrB = temp;
}
int main(){
int stringa[40] = {100,101,102,103,104,105,106,107,108,109,110,-1};
int stringb[40] = {0};
int *ptr;
int *ptr1;
int len = 0;
ptr = stringa;
ptr1 = stringb;
while(*ptr != -1){
*ptr++;len++;
}
printf("\n len : %d \n",len);
int_copy(stringa,stringb,len);
while(*ptr1 != -1){
printf("%d\t",*ptr1);
*ptr1++;
}
return 0;
}
Run Code Online (Sandbox Code Playgroud)
我正在尝试一个示例程序将整数数组复制到另一个整数数组.还有另一种方法可以更有效地完成它.
编辑:
void int_copy(int* ptrA,int* ptrB,int nbr){
memcpy(ptrA,ptrB,(sizeof(int)*nbr));
}
Run Code Online (Sandbox Code Playgroud)