即使在转换了一个void指针之后,我在解除引用时也遇到了编译错误.有谁能请让我知道这个的原因.
int lVNum = 2;
void *lVptr;
lVptr = (int*)&lVNum;
printf("\nlVptr[60 ] is %d \n",lVptr[1]);
Run Code Online (Sandbox Code Playgroud) 有人请告诉我以下使用sealed不编译的原因吗?然而,如果我更换sealed与final和编译如Java,它的工作原理.
private sealed int compInt = 100;
public bool check(int someInt)
{
if (someInt > compInt)
{
return true;
}
return false;
}
Run Code Online (Sandbox Code Playgroud) 当我打印这样的联合大小时:
union u {
char c[5];
int i;
} un;
Run Code Online (Sandbox Code Playgroud)
使用这个:
int _tmain(int argc, _TCHAR* argv[])
{
printf("size of union = %d ",sizeof(un));
return 0;
}
Run Code Online (Sandbox Code Playgroud)
我使用Visual C++得到了8的答案,但我预计为什么?为什么?
嗯,对于同样的例子,我做了这样的事情:
int i1 = 0x98761234;
un.i = i1;
printf("\n un.c[0] = %x ",un.c[0]);
printf("\n un.c[1] = %x ",un.c[1]);
printf("\n un.c[2]= %x ",un.c[2]);
printf("\n un.c[3] = %x ",un.c[3]);
printf("\n un.c[4] = %x ",un.c[4]);
printf("size of union = %d ",sizeof(un));
Run Code Online (Sandbox Code Playgroud)
我得到了结果
un.c[0] = 34;
un.c[1] = 12;
un.c[2] = 76;
un.c[3] = ffffff98;
Run Code Online (Sandbox Code Playgroud)
为什么un.c有6fs …
有没有办法在不使用C中的临时变量的情况下反转链表?提前致谢.
着名的方法:
Element *reverse(Element *head)
{
Element *previous = NULL;
while (head != NULL) {
// Keep next node since we trash
// the next pointer.
Element *next = head->next;
// Switch the next pointer
// to point backwards.
head->next = previous;
// Move both pointers forward.
previous = head;
head = next;
}
return previous;
}
Run Code Online (Sandbox Code Playgroud)
使用临时变量
SAURABH
我正在尝试使用 rusage 测量各种函数调用的资源使用时间(用户和系统)。我发现我得到的结果大约是 10 毫秒,如 0 70000us、10000us 等。请告诉我是否有办法为 getrusage 设置精度/粒度。
我的程序很简单:
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include <sys/time.h>
#include <sys/resource.h>
#include <unistd.h>
int main(){
struct rusage usage;
struct timeval start, end;
int i, j, k = 0;
getrusage(RUSAGE_SELF, &usage);
start = usage.ru_utime;
printf("buffer check\n");
char *str = "---";
int arr[100],ctr;
for(ctr = 0;ctr<100;ctr++){
arr[ctr] = ctr + 1000;
}
for (i = 0; i < 10000; i++) {
for (j = 0; j < 10000; j++) {
k += 20;
}
} …Run Code Online (Sandbox Code Playgroud) 我在使用相对路径的fopen()时遇到了麻烦.我想像这样使用fopen:
fopen("\\Saurabh\\pqrs.txt");
Run Code Online (Sandbox Code Playgroud)
我得到filePointer为null.
出现这种情况是因为我正在尝试创建一个必须读取文件的设置或部署项目.用户执行安装后默认选择的文件路径是C:\ Program Files\Setup ..(其中exe被转储).所以我将文件转储到同一个文件夹中,并为程序中的那些文件提供路径(固定路径或硬编码).
如果用户选择其他路径进行安装,则程序将失败.
有什么办法可以解决这个问题吗?
任何人都可以告诉我一个Windows 7的shell命令,它将文件路径作为参数并返回该文件的大小 - 类似于:
fileSize.cmd file.txt
Run Code Online (Sandbox Code Playgroud)
......这会给我1KB.
SO中的一个问题指出了命令echo %~z1,但为此,我必须编写一个单独的批处理文件并在其中使用此命令.我正在考虑修改现有的bat文件并以某种方式合并此命令.我的批处理文件如下所示:
p4 diff //sources/j2cs/output.txt >> diff_out.txt
Run Code Online (Sandbox Code Playgroud)
我必须在现有的bat文件中添加上面的命令来查找文件大小diff_out.txt.
c ×3
c++ ×2
batch-file ×1
c# ×1
file-io ×1
filesize ×1
java ×1
linked-list ×1
linux ×1
pointers ×1
sealed ×1
unions ×1
visual-c++ ×1
windows-7 ×1