c - Memory questions and functions -


hope you're having great summer!

i'm revising exams , have come couple of questions on past paper stuck , appreciate help/explanation can provide! :)

here questions;

1.) function power() should implement function n* 2^p (the output of printf() line should 5*(2^2) = 20). complete body of function power() using shift operator. why sensible use shift operator instead of available power function in math.h?

#include <stdio.h>  int power(int n, int p) {     << code goes here >> }  main () {     printf("%d*(2^%d) = %d\n",5,2,power(5,2)); } 

2.) memory organized in regions called text, data, stack , heap. program below defines variables a, b , c. in memory region content of each variable reside?

#include <stdio.h> #include <stdlib.h>  int = 5;  int func1(int x) {     int b=5; }  main {     char * c;      c = (char*) malloc (a+1);     func1(a);     return 0; } 

i have couple more questions ask see how these goes! i've never used stackoverflow before please go easy if i've done wrong!

many thanks,

dan

1 -

because question wants show how work our power using shift operator; not show know how use c runtime library.

2

a - data b - stack c - stack 

he wants c - heap thats not case. contents of c on stack


Comments

Popular posts from this blog

ios - UICollectionView Self Sizing Cells with Auto Layout -

node.js - ldapjs - write after end error -

DOM Manipulation in Wordpress (and elsewhere) using php -