All Exams Test series for 1 year @ ₹349 only
Question

#include <stdio.h>

void foo(int *p, int x){
    *p = x;
}

int main(){
    int *z;
    int a = 20, b = 25;
    z = &a;
    foo(z, b);
    printf("%d", a);
    return 0;
}
The output of the given C program is __________. (Answer in integer)

#include <stdio.h>
void foo(int *p, int x){
    *p = x;
}
int main(){
    int *z;
    int a = 20, b = 25;
    z = &a;
    foo(z, b);
    printf("%d", a);
    return 0;
}
The given C program demonstrates the use of pointers and function calls to modify values. Here's a step-by-step explanation:
1. The function foo(int *p, int x) takes a pointer to an integer p and an integer x. It sets the value pointed to by p to x. This operation means that the integer at the memory location p is updated to x.
2. In main(), two int variables a and b are initialized with values 20 and 25 respectively.
3. A pointer z is assigned the address of a (z = &a;), making z point to a.
4. The function foo is called with arguments z and b. Since z points to a, calling foo(z, b) effectively sets a to the value of b, which is 25.
5. The printf statement outputs the value of a.
6. Since a is modified to 25, the output of the program is 25, which falls within the specified range (25, 25).
Final Output: 25
Was this answer helpful?

Important Questions from Array

  1. Which of the following expression will delete the entire array pointed to by q?

  2. Consider the following C program segment.

    #include <stdio.h>

    int main()
    {
      char s1[7] = "1234";
        char *p;

        p = s1 + 2;
        *p = '0';

        printf("%s", s1);

        return 0;
    }

    What will be printed by the program?
  3. Consider an array $A$ of integers of size $n$. The indices of $A$ run from 1 to $n$. An algorithm is to be designed to check whether $A$ satisfies the condition given below.

    $\forall i,j \in \{1, \dots, n-1\}$ such that $i > j$, $(A[i + 1] - A[i]) > (A[j + 1] - A[j])$

    Which one of the following gives the worst case time complexity of the fastest algorithm that can be designed for the problem?
  4. What is the output the given C language code snippet? 

    #include<stdio.h>

     int main()

    {

     int x[] = {10,20,30}; 

    int *p = x; 

    p++; 

    printf("%d",*p); 

    return 0; 

    }

Need Expert Advice?

Start Your Preparation with Prepp Mobile App

Download the app from Google Play & App Store
Download the app from Google Play & App Store
Prepp Mobile App