What is the output of the following. Explain why this
output was obtained.
int k[3] = { 10, 20, 30 };
int *kp;
kp = k;
printf("%d\n", *kp + 2);
printf("%d\n", *(kp + 2));
Find the output of the following:
double z = 56.4;
double *p;
p = &z;
printf("%lf\n", *p / 2);
Suppose the following array has already been declared.
Declare a pointer to this array and then use the pointer in a loop
to multiply each array value by 2.
int ar[] = { 28, 95, -45, 67, -61 };
int k[3] = { 10, 20, 30 };
int *kp;
kp = k;
printf("%d\n", *kp + 2);
printf("%d\n", *(kp + 2));
Output:-
12
30
Explanation:-
IN the first printf statement , *kp is pointing to the initial value of the array i.e. 10 so *kp will hold the value 10 and adding 2 will result in 12.
In the next printf statement , kp is holding the address of first element of array adding 2 will point to the 3rd element of array so *(kp+2) will give 30
=================================================================
double z = 56.4;
double *p;
p = &z;
printf("%lf\n", *p / 2);
Output:-
28.200000
Explanation:-
p is storing the address of z , so *p will hold the value of z i.e. 56.4 . so dividing by 2 will result in 28.2
=================================================================
Please Refer to the code below:-
#include <stdio.h>
int main()
{
// Declaring std::array<T, N> ;
int ar[] = { 28, 95, -45, 67, -61 };
// Declaring pointer and loop variable
int *kp,i;
// Finding size of array
int n = sizeof(ar)/sizeof(ar[0]);
// initializing pointer
kp =ar;
// multiplying array by 2 using pointer
for(i=0;i<n;i++)
{
ar[i]=*(kp+i)*2;
}
// printing array
for(i=0;i<n;i++)
{
printf("%d\n", ar[i]);
}
return 0;
}
Output:-
56
190
-90
134
-122
Please Refer to the images below:-


===============================================
Please upvote
==============================================
What is the output of the following. Explain why this output was obtained. int k[3] =...
QUESTION 9 What will be the output of following code snippet? int a[3] = {1, 2, 3}; int *p = a; int **r = &p; printf("%p %p", *r, a); A. Different memory addresses printed B. 1 2 C. Same memory address printed twice D. 1 1 2 points QUESTION 10 What will be the output of following code snippet? int arr[4] = {1, 2, 3, 4}; int *p; p = arr + 3; *p = 5; printf("%d\n", arr[3]); A....
20) What is the output of the following segment of C code: int avg(int n, int* a); int main () { int array[4]={1,0,6,9}; printf("%d", avg(4, array)+ 1); system("pause"); return 0; } int avg(int n, int* a) { int i, sum=0; for (i=0;i<n;i++) { sum+=a[i]; } return sum/n; } a) 16 b) 5 c) 4 d) 8 21) What is the output of the following segment of C code: int x = 2; int y = 3;...
Need help with these questions in C programming:
9. What is the output of the following code? int X[10]={0}; int N=4; for(int k=0; k<N:k++) X[k] = k*2: printf("%d", X[N/2]; 10. Write a single statement to accomplish each of the following. Assume that each of these statements applies to the same program. a. Write a statement that opens file "oldmast.dat" for reading and assigns the returned file pointer to ofPtr. b. Write a statement that opens file "trans.dat" for writing and...
Write a C program to do the following...in this EXACT order: a. Declare an integer array named alpha of 50 elements. b. Use a for loopt to initialize each element of alpha to its index value (e.g. alpha[0] = 0, alpha[1]=1, etc.). c. Output the value of the first element of the array alpha. d. Output the value of the last element of alpha. e. Set the value of the 25th element of the array alpha to 62 and output...
the
answer should be in C
What is the output of the following: int whatIsThat(int * x); int main() int hold; int x[] = { 2,4,6,8); hold = whatIsThat(x); printf("%d, %d\n", x[0], hold); return 0; } int whatIsThat(int * a) { int i,sum=0; a[0] = a[O] + 6; for(i = 0; i <= 2; i++) (sum+= a[i]; a[i] = a[i] + 12; return sum; a. 20, 20 b. 20, 18 c. 18, 18 d. none of above What is the...
what is output
#include<stdio.h> pint main() { int i, j, total; for ( 2 { printf("\n"); for ( 2 { total = i + j; printf("%d", total); بہا } getchar(); return 0; } Find the for loop content | Output of progrm 5 15 1 11 21 31 41 51 61 2 12 22 32 25 3 13 23 33 43 53 63 4 14 24 34 44 54 64 35 45 6 16 26 36 46 56 66 7...
What is the output of the following C program? int x=1, y=2; int * const ptr = &x; ptr = &y; printf("%d\n", *ptr); What is the output of the following C program? int x=1, y=2; const int * ptr = &x; ptr = &y; printf("%d\n", *ptr); What is the output of the following C program? int x=1, y=2; int * ptr = &x; ptr = &y; printf("%d\n", *ptr); What is the output of the following C program? int x=1, y=2;...
What is the output of the following? int sum=3, z=1; do { printf("The sum:%d*", sum+z); } while (sum<= 1); printf("0"); * 1 (2 Points) 40 4
C Programming
What is the output of the following code? int x=5: x * = 3: printf("%d\n", x): x++: ++x: x = x/2: printf("%d\n", x): printf("%d\n", x++): printf("%d\n", ++x);
(15 pts) Using the following example, int a, p=&a; *p = 20; Give the two major differences of * and & in the above example. (35 pts) Do the following in a program segment step by step. The next step uses the results of the previous step and earlier, using a single statement only and none for manual work. Declare an array called a of float of size 10 and initialize it to 2.5, -3.3, 5.9, 1.0, 3.5, 4.3, -7.3,...