1.What is the output of the program A. 0, 0.000000 Explanation: When an automatic structure is partially initialized remaining elements are initialized to 0(zero). struct emp e = {“Tiger”, 5, 1500.50}; // Full Initialization struct emp e = {“Tiger”}; // Partial Initialization struct emp e ; // No Initialization 2.What will be the output of the program? #include<stdio.h> Explanation: 32<<1 means 0010 0000 are add +1 0100 0000 = 64. 32<<0 means 0010 0000 are add +0 0010 0000 = 32. 32<<-1 means 0010 0000 Zero -1 0000 0000 = 0. 32<<-0 means 0010 0000 L less -0 0010 0000 = 32. 32>>-1 means 0010 0000 Zero -1 0100 0000 = 64. 32>>-0 means 0010 0000 L less -0 0010 0000 = 0. 3.What will be the output of the program, if a short int is 2 bytes wide? A. 1 … 65535 Explanation: for(i<=5 && i>=-1; ++i; i>0) so expression i<=5 && i>=-1 initializes for loop. expression ++i is the loop condition. expression i>0 is the increment expression. In for( i <= 5 && i >= -1; ++i; i>0) expression i<=5 && i>=-1 evaluates to one. Loop condition always get evaluated to true. Also at this point it increases i by one. An increment_expression i>0 has no effect on value of i.so for loop get executed till the limit of integer (ie. 65535) 4.What will be the output of the program ? Explanation: 5.Point out the error in the program? A. Error: Lvalue required/incompatible types in assignment Explanation: We have to use strcpy(char *dest, const char *source) function to assign a string. Ex: strcpy(e.name, “Suresh”);#include<stdio.h> int main() { struct emp { char name[20]; int age; float sal; }; struct emp e = {"Tiger"}; printf("%d, %fn", e.age, e.sal); return 0; }
B. Garbage values
C. Error
D. None of above
If we use: printf(“%s %d, %fn”, e.name, e.age, e.sal);
//Ouput: Tiger, 25, 1500.500000
//Ouput: Tiger, 0, 0.000000
//Ouput: GarbageValue, GarbageValue, GarbageValue!int main() { printf("%d %dn", 32<<1, 32<<0); printf("%d %dn", 32<<-1, 32<<-0); printf("%d %dn", 32>>1, 32>>0); printf("%d %dn", 32>>-1, 32>>-0); return 0; }
In case:#include<stdio.h> int main() { short int i = 0; for(i<=5 && i>=-1; ++i; i>0) printf("%u,", i); return 0; }
B. Expression syntax error
C. No output
D. 0, 1, 2, 3, 4, 5#include<stdio.h> int main() { static int arr[] = {0, 1, 2, 3, 4}; int *p[] = {arr, arr+1, arr+2, arr+3, arr+4}; int **ptr=p; ptr++; printf("%d, %d, %dn", ptr-p, *ptr-arr, **ptr); *ptr++; printf("%d, %d, %dn", ptr-p, *ptr-arr, **ptr); *++ptr; printf("%d, %d, %dn", ptr-p, *ptr-arr, **ptr); ++*ptr; printf("%d, %d, %dn", ptr-p, *ptr-arr, **ptr); return 0; }
p is an array of pointers. ptr is a pointer to a pointer, initailly referring to p.
Step 1:
ptr++
ptr is incremented by 1, i.e. ptr now points to p+1 or (arr+1)
ptr-p=1, *ptr=arr+1, so ptr-arr=1, **ptr=(arr+1)=1
Step 2:
*ptr++
is *(ptr++), i.e. ptr=ptr+1=arr+2, the * part is not of any work here.
ptr-p=2, *ptr=arr+2, so ptr-arr=2, **ptr=(arr+2)=2
Step 3:
*++ptr
Similar to step 2, ++ptr=(++ptr)
ptr-p=3, *ptr=arr+3, so ptr-arr=3, **ptr=(arr+3)=3
Step 4:
++*ptr
is ++(*ptr), i.e. ptr now points to arr+4, but point to be noted that *p also changes,since ptr is pointer to p. Here ptr does not change its reference position unlike all the other steps, but changes the value it is pointing to
*p[]={arr, arr+1, arr+2, arr+4, arr+4}
so, ptr-p=3, *ptr=p[3]=arr+4, so ptr-arr=4, **ptr=(arr+4)=4#include<stdio.h> int main() { struct emp { char name[25]; int age; float bs; }; struct emp e; e.name = "Suresh"; e.age = 25; printf("%s %dn", e.name, e.age); return 0; }
B. Error: invalid constant expression
C. Error: Rvalue required
D. No error, Output: Suresh 25
We cannot assign a string to a struct variable like e.name = “Suresh”; in C.
本网页所有视频内容由 imoviebox边看边下-网页视频下载, iurlBox网页地址收藏管理器 下载并得到。
ImovieBox网页视频下载器 下载地址: ImovieBox网页视频下载器-最新版本下载
本文章由: imapbox邮箱云存储,邮箱网盘,ImageBox 图片批量下载器,网页图片批量下载专家,网页图片批量下载器,获取到文章图片,imoviebox网页视频批量下载器,下载视频内容,为您提供.
阅读和此文章类似的: 全球云计算