Consider following C program : #include<stdio.h> int main() { int x[]={2, 4, 6, 8, 10}; int a, b=0, *y=x+4; for(a=0; a<5; a++) { b=b+(*y-a)-*(y-a); } printf("%d\n", b); return 0; } What will be the output of the above C program ?
10
y = x + 4 points to x[4] = 10. In the loop, (*y - a) subtracts a from the value 10, while *(y - a) moves the address back a places and reads x[4 − a].
| a | *y − a | *(y − a) | term | b |
|---|---|---|---|---|
| 0 | 10 | x[4] = 10 | 0 | 0 |
| 1 | 9 | x[3] = 8 | 1 | 1 |
| 2 | 8 | x[2] = 6 | 2 | 3 |
| 3 | 7 | x[1] = 4 | 3 | 6 |
| 4 | 6 | x[0] = 2 | 4 | 10 |
Step 1 — Each iteration adds a, so b = 0 + 1 + 2 + 3 + 4 = 10, and printf prints 10.
4 is only the last term, 6 stops after a = 3, and 8 comes from mis-reading one of the elements; the full five-iteration sum is 10.
10 option is correct.
What does the following expression means ?
char *(*(* a[N]) ( )) ( );
What is the output of the following program ?
(Assume that the appropriate preprocessor directives are included and there is no syntax error)
main ( )
{ char S[ ]="ABCDEFGH";
printf ("%C", * (& S[3]));
printf ("%s", S+4);
printf ("%u", S);
/* Base address of S is 1000 */
}
#include<stdio.h>
void main()
{
int arr[]={1, 2, 3, 4, 5};
int *p=arr;
printf("%d", *p++);
printf("%d", *(p+1));
}
Find the output of the above code?
Consider the following code :
#include<stdio.h>
void f1(char *x, char *y) {
char *t1; t1=x; x=y; y=t1;}
void f2(char **x, char **y) {
char *t1; t1=*x; *x=*y; *y=t1;}
int main()
{
char *a="ONE", *b="TWO";
f1(a, b); printf("%s %s", a, b);
f2(&a, &b); printf("%s %s", a, b);
return 0;
}
What will be the output of the above code?
Which of the following is correct way to declare a functional pointer in C ?
What will be the output of the following C code?
#include<stdio.h>
void main()
{
int arr[5] = {10, 20, 30, 40, 50};
int *p = (int*) (&arr + 1);
printf("%d%d", *(arr + 1), *(p - 1));
}
Which of the following statements about pointers in C are TRUE.
(A) Pointers can be used to access array elements
(B) Pointers can store the address of another pointer
(C) Pointers are automatically deferenced in expression
(D) Pointers cannot be used to access structure members
Choose the correct answer from the options given below :
What is the output of the following C programming language code?
#include<stdio.h>
int main()
{
int x = 10;
int *p = &x;
*p = *p + 5;
printf("%d %d", x, *p);
return 0;
}
Consider the following ANSI-C program.
#include <stdio.h>
int main(){
int *ptr, a, b, c;
a=5; b=11; c=20;
ptr=&a; *ptr=c; ptr=&c;
a=*(&b); c=*ptr-a;
printf("%d",c);
return(0);
}
The output of this program is ____________. (answer in integer)
Note: Assume that the program compiles and runs successfully.
Consider the following C program:
#include <stdio.h>
void stringcopy(char *, char *);
int main(){
char a[30] = "@#Hello World!";
stringcopy(a, a + 2);
printf("%s\n", a);
return 0;
}
void stringcopy(char *s, char *t) {
while(*t)
*s++ = *t++;
}
Which ONE of the following will be the output of the program?
Consider the following C program:
#include <stdio.h>
int main(){
int a;
int arr[5] = {30,50,10};
int *ptr;
ptr = & arr[0] + 1;
a = *ptr;
(*ptr)++;
ptr++;
printf("%d", a + (*ptr) + arr[1]);
return 0;
}
The output of the above program is ____________ (Answer in integer)