C语言sizeof和三元运算符

#include <stdio.h>

main() {

   int a = 4;
   short b;
   double c;
   int* ptr;

   /* example of sizeof operator */
   printf("Line 1 - Size of variable a = %d/n", sizeof(a) );
   printf("Line 2 - Size of variable b = %d/n", sizeof(b) );
   printf("Line 3 - Size of variable c= %d/n", sizeof(c) );

   /* example of & and * operators */
   ptr = &a;    /* 'ptr' now contains the address of 'a'*/
   printf("value of a is  %d/n", a);
   printf("*ptr is %d./n", *ptr);

   /* example of ternary operator */
   a = 10;
   b = (a == 1) ? 20: 30;
   printf( "Value of b is %d/n", b );

   b = (a == 10) ? 20: 30;
   printf( "Value of b is %d/n", b );
}

原创文章,作者:ItWorker,如若转载,请注明出处:https://blog.ytso.com/265119.html

(0)
上一篇 2022年6月7日
下一篇 2022年6月7日

相关推荐

发表回复

登录后才能评论