int arr[] = {1,2,3,4};
char arr[] = {'a','b','c',0};
#include "stdio.h"
int main()
{
/*
author: www.nowamagic.net
*/
int i, length;
int arr[] = {1,2,3,4};
length = sizeof(arr) / sizeof(int);
printf("sizeof(arr)为:%d\n", sizeof(arr));
printf("sizeof(int)为:%d\n", sizeof(int));
printf("数组长度为:%d\n", length);
for(i = 0; i < length; i++)
{
printf("%d\n", arr[i]);
}
return 0;
}
sizeof(arr)为:16 sizeof(int)为:4 数组长度为:4 1 2 3 4
#include "stdio.h"
int main()
{
/*
author: www.nowamagic.net
*/
int i, length;
char arr[] = {'a','b','c',0};
length = sizeof(arr) / sizeof(char);
printf("sizeof(arr)为:%d\n", sizeof(arr));
printf("sizeof(char)为:%d\n", sizeof(char));
printf("数组长度为:%d\n", length);
for(i = 0; i < length; i++)
{
printf("%c\n", arr[i]);
}
return 0;
}
sizeof(arr)为:4 sizeof(char)为:1 数组长度为:4 a b c
#include <stdio.h>
#include <stdlib.h>
#include <mpi.h>
#include <string.h>
#define K 15
#define DIM 10
#define LOOP 1000000
int main(int argc, char** argv)
{
double o_centers[K*DIM];
int i = 0, j = 0, k = 0;
MPI_Init(&argc, &argv);
printf("Start to test array assign...\n");
double starttime1 = MPI_Wtime();
for(k = 0; k < LOOP; k++)
for(i = 0; i < K; i++)
for(j = 0; j < DIM; j++)
o_centers[j + i*DIM] = 0;
double endtime1 = MPI_Wtime();
printf("Array assign takes %5.12f seconds...\n", endtime1 - starttime1);
printf("Start to test memset assign...\n");
double starttime2 = MPI_Wtime();
for(k = 0; k < LOOP; k++)
memset(o_centers, 0, K*DIM*sizeof(double));
double endtime2 = MPI_Wtime();
printf("Memset assign takes %5.12f seconds...\n", endtime2 - starttime2);
MPI_Finalize();
return 0;
}
Start to test array assign... Array assign takes 0.624787092209 seconds... Start to test memset assign... Memset assign takes 0.052299976349 seconds...
int arr[8]={1,2,3,4};
int arr[8]={1,2,3,4,0,0,0,0};
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有