Variables and Keywords in C – GeeksforGeeks<\/a><\/em><\/p>\nExample code<\/p>\n
var.c<\/strong><\/p>\n\u00a0<\/p>\n\n\n
#include <stdio.h>\n\nint a=1; \/\/ initialized global variable.\nint b; \/\/ uninitialized global variable.\n\nstatic int c; \/\/global static variable.\nextern int d;\n\ntypedef struct _abc{\nchar a;\nshort b;\nint c;\n}ABC;\n\ntypedef union _def{\nchar a;\nshort b;\nint c;\n}DEF;\n\nint increment()\n{\nstatic int p = 5;\na=a+1;\np=p+1;\n\nprintf(\"dataof(p)=%d\\n\", p);\nreturn 0;\n}\n\nint main(int argc, char * argv[])\r\n{\r\nauto int e=5; \/\/auto variable\r\nint f=6; \/\/local variable\r\nconst int g=7; \/\/ constant variable\r\nlong j=10; \/\/ long type variable\r\nlong long k=11; \/\/ long long type variable\r\nABC h; \/\/ structure type variable\r\nDEF i; \/\/ union type variable\r\nchar l='a'; \/\/ character type variable\r\nshort m=10; \/\/ short type variable\r\nchar *n=&l; \/\/ pointer variable.\r\nvoid *o=(void *)n; \/\/ void pointer variable.\n\/\/ Size check\r\nprintf(\"Size of char is %d bytes\\n\", sizeof(l));\r\nprintf(\"Size of short is %d bytes\\n\", sizeof(m));\r\nprintf(\"Size of int is %d bytes\\n\", sizeof(f));\r\nprintf(\"Size of long is %d bytes\\n\", sizeof(j));\r\nprintf(\"Size of long long is %d bytes\\n\", sizeof(k));\r\nprintf(\"Size of pointer is %d bytes\\n\", sizeof(n));\r\nprintf(\"Size of structure ABC is %d bytes\\n\", sizeof(h));\r\nprintf(\"Size of union DEF is %d bytes\\n\", sizeof(i));\r\n\r\n\/\/Access check\r\nincrement();\r\nincrement();\r\nprintf(\"dataof(a)=%d, addressof(a)=0x%x\\n\", a, &a);\r\nprintf(\"dataof(b)=%d, addressof(b)=0x%x\\n\", b, &b);\r\nprintf(\"dataof(c)=%d, addressof(c)=0x%x\\n\", c, &c);\r\nprintf(\"dataof(d)=%d, addressof(d)=0x%x\\n\", d, &d);\r\nprintf(\"dataof(e)=%d\\n\", e);\r\nprintf(\"dataof(f)=%d\\n\", f);\r\n\/\/ g = g+10; in correct as its a constant \r\nprintf(\"dataof(g)=%d\\n\", g);\r\nprintf(\"dataof(j)=%d\\n\", j);\r\nprintf(\"dataof(k)=%d\\n\", k);\n\nreturn 0;\n}<\/code><\/pre>\n\n\n\n
<\/p>\n\n\n\n
ext.c<\/strong><\/p>\n\n\n\nint d = 4;<\/code><\/pre>\n\n\n\n<\/p>\n\n\n\n
compilation<\/strong><\/p>\n\n\n\n<\/p>\n\n\n\n
gcc -o test var.c ext.c<\/code><\/pre>\n\n\n\nOutput<\/strong><\/p>\n\n\n\nyogi@localhost devel]$ .\/test\r\nSize of char is 1 bytes\r\nSize of short is 2 bytes\r\nSize of int is 4 bytes\r\nSize of long is 8 bytes\r\nSize of long long is 8 bytes\r\nSize of pointer is 8 bytes\r\nSize of structure ABC is 8 bytes\r\nSize of union DEF is 4 bytes\r\ndataof(p)=6\r\ndataof(p)=7\r\ndataof(a)=3, addressof(a)=0x601024\r\ndataof(b)=0, addressof(b)=0x601038\r\ndataof(c)=0, addressof(c)=0x601034\r\ndataof(d)=4, addressof(d)=0x60102c\r\ndataof(e)=5\r\ndataof(f)=6\r\ndataof(g)=7\r\ndataof(j)=10\r\ndataof(k)=11<\/code><\/pre>\n\n\n\n<\/p>\n","protected":false},"excerpt":{"rendered":"
Variables are used to store data.\u00a0 The following are the charateristics for the variable. Variables will have unique names under a specific scope. Variable data type defines the storage requirement for the variable. Storage class of the variable defines the visibility and lifetime of the variable in a program or function or block. The following […]<\/p>\n","protected":false},"author":29,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1337],"tags":[1333],"class_list":["post-2207","post","type-post","status-publish","format-standard","hentry","category-my-article","tag-programming-2"],"_links":{"self":[{"href":"http:\/\/blog.yogindar.org\/index.php?rest_route=\/wp\/v2\/posts\/2207","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/blog.yogindar.org\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/blog.yogindar.org\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/blog.yogindar.org\/index.php?rest_route=\/wp\/v2\/users\/29"}],"replies":[{"embeddable":true,"href":"http:\/\/blog.yogindar.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=2207"}],"version-history":[{"count":3,"href":"http:\/\/blog.yogindar.org\/index.php?rest_route=\/wp\/v2\/posts\/2207\/revisions"}],"predecessor-version":[{"id":2210,"href":"http:\/\/blog.yogindar.org\/index.php?rest_route=\/wp\/v2\/posts\/2207\/revisions\/2210"}],"wp:attachment":[{"href":"http:\/\/blog.yogindar.org\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=2207"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/blog.yogindar.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=2207"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/blog.yogindar.org\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=2207"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}