[go: up one dir, main page]

0% found this document useful (0 votes)
401 views7 pages

What Happens If You Try To Compile and Run This Program?: Pregunta 2

The program declares functions add, add2, and main. In main it initializes an integer var to 0, calls add2 to set var to 6, calls add to double var to 12, and calls add2 again to add var to itself, setting it to 24. It then prints 24.

Uploaded by

Adrian Jiménez
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
401 views7 pages

What Happens If You Try To Compile and Run This Program?: Pregunta 2

The program declares functions add, add2, and main. In main it initializes an integer var to 0, calls add2 to set var to 6, calls add to double var to 12, and calls add2 again to add var to itself, setting it to 24. It then prints 24.

Uploaded by

Adrian Jiménez
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 7

What happens if you try to compile and run this program?

    #include <stdio.h>


    int add(int par) {
        par += par;
        return par;
    }
    int add2(int p1, int p2) {
        return p1 + p2;
    }
    int main(void) {
        int var = 0;
        var = add2(2,4);
        var = add(var);
        var = add2(var,var);
        printf("%d",var);
        return 0;
    }

  
the program outputs 24
 

  
the program outputs 72
 

  
the program outputs 48
 
 
Pregunta 2
1 / 1 ptos.
What happens if you try to compile and run this program?

    #include <stdio.h>


    int add(int par) {
        par += par;
        return par;
    }
    int add2(int p1, int p2) {
        return p1 + p2;
    }
    int main(void) {
        int var = 0;
        var = add2(add(2),add(4));
        var = add2(var,var);
        printf("%d",var);
        return 0;
    }

  
the program outputs 48
 

  
the program outputs 24
 

  
the program outputs 12
 
 
Pregunta 3
1 / 1 ptos.
What happens if you try to compile and run this program?

    #include <stdio.h>


    int f1(int v) {
        v *= v;
        return v;
    }
    int f2(int p1, int p2) {
        return p1 / p2;
    }
    int main(void) {
        int v = 0;
        f1(f1(f2(2,4)));
        printf("%d",v);
        return 0;
    }

  
the program outputs 8
 

  
the program outputs 0
 

  
the program outputs 6
 
 
Pregunta 4
1 / 1 ptos.
What happens if you try to compile and run this program?

    #include <stdio.h>


    #include <string.h>
    void f(char *s) {
        s[1\] = '\0';
    }
    int main(void) {
        char p1[\] = "ABC", p2[\] = "XYZ";
        f(p1);
        f(p2);    
        printf("%d",strlen(p1) + strlen(p2));
        return 0;
    }

  
the program outputs 1
 

  
the program outputs 0
 

  
the program outputs 2
 
 
Pregunta 5
1 / 1 ptos.
What happens if you try to compile and run this program?

    #include <stdio.h>


    #include <string.h>
    void cp(char *p1,char *p2) {
        int i,j;
    
        j = 0;
        for(i = 0; i < strlen(p2); i += 2)
                p1[j++\] = p2[i\];
        p1[j\] = '\0';
    }
    int main(void) {
        char str[100\];
    
        cp(str,"ABCD");
        printf("%s",str);
        return 0;
    }

  
the program outputs AB
 

  
the program outputs AC
 

  
the program outputs AD
 
 
IncorrectoPregunta 6
0 / 1 ptos.
What happens if you try to compile and run this program?

    #include <stdio.h>


    int fun(int n) {
        return n   1;
    }
    int main(void) {
        printf("%d",fun(fun(fun(fun(fun(3))))));
        return 0;
    }

  
the program outputs 0
 

  
the program outputs -2
 

  
the program outputs -1
 
 
Pregunta 7
1 / 1 ptos.
What happens if you try to compile and run this program?

    #include <stdio.h>


    int fun(int n) {
        if(n == 0)
            return 0;
        return n + fun(n   1);
    }
    int main(void) {
        printf("%d",fun(3));
        return 0;
    }

  
the program outputs 3
 

  
the program outputs 1
 

  
the program outputs 6
 
 
IncorrectoPregunta 8
0 / 1 ptos.
What happens if you try to compile and run this program with the following
command?
prog MARY HAD A LITTLE LAMB

    #include <stdio.h>


    #include <string.h>
    int main(int argc, char *argv[\]) {
        printf("%d", argc + strlen(argv[1\]));
        return 0;
    }

  
the program outputs 8
 

  
the program outputs 6
 

  
the program outputs 10
 
 
Pregunta 9
1 / 1 ptos.
What happens if you try to compile and run this program?

    #include <stdio.h>


    char fun(char *n, int m) {
        return *(n + 2 * m);
    }
    int main(void) {
        printf("%c",fun("aAbBcCdD",1));
        return 0;
    }

  
the program outputs a
 

  
the program outputs 0
 

  
the program outputs b
 
 
Pregunta 10
1 / 1 ptos.
What happens if you try to compile and run this program?

    #include <stdio.h>


    char fun(char *n, int m) {
        return (m+2)[n\];
    }
    int main(void) {
        printf("%c",fun("aAbBcCdD",1));
        return 0;
    }
  
the program outputs A
 

  
the program outputs C
 

  
the program outputs B
 

Anterior Siguiente
Información sobre el último intento:
10
Tiempo:
minutos

Calificación actual: 8 de 10

se mantuvo la
8 de 10
calificación:
Aún dispone de 2 intentos más
Volver a realizar la evaluación

You might also like