Hello So I want to echo the idea of having some kind of note-taking device your phone or laptop works, too I hate paper But some people love paper so no offense if you like it we're going to talk about I need to project more Can you hear me in the back? Barely all right. I need to project more all right So we are going to be talking about data-driven marketing with WordPress and laying some foundations for that If my clicker worked hey, it did All of my fonts look crazy on here because originally it was set for 16 by 9 and these projectors are not that so enjoy the font show That's me. I organized the Raleigh SEO meetup I also host a WordPress help desk in Raleigh and I help businesses Build their WordPress websites at opsis.com So we're going to go over some of the fundamentals of online marketing So we have an idea of what we're going to talk about today how to measure your success with online marketing common goals and ways to connect those goals with KPI and ROI We're also going to talk about how to avoid technical common technical challenges and Some places to go for more information and guidance So I've got some quick questions for y'all. This is where you're going to need that note-taking device so you can answer these questions What do you want people to do when they come to your website? Take a few seconds jot down whatever that number one thing is that you want people to do and then if anybody wants to holler them out we can Share a couple of them real quick Anybody want to share with the crowd? Okay, you wanted to follow your website Wanted to buy something Do you have an e-commerce site and your manufacturer? Okay, so they actually buy on the website Okay, so there may be a multiple step process there who else Answer a call to action. Okay, so you're taking the content marketing stuff around here. I presume who else just throw some out Make an appointment Engage, okay Next one Why do you want people to do that? There we go. Now we're getting somewhere. So follow the website so that way you'll get paid So there's actually something else that you want people to do follow the website as the backup option depends on your business model You want them to return? Yeah Anybody else want to throw one out why you want them to do that so that's what to do Why do you want them to do that? Of course making money helping people all right and How does this impact the bottom line of your business? This is what all of this is getting to oftentimes I hear from Potential clients that they want more followers on Facebook as an example last time I checked you can't pay your rent with Facebook followers So it all gets down to how does this impact the bottom line of your business and being clear on how you're building that model? And how you're optimizing towards that goal So we're going to measure success in order to figure out where we're going with this Quick little example to show you what a dashboard could look like if you're measuring some goals You can see the light blue line. This is organic search referrals So you can see spikes and dips as people are coming in off of search engine optimization into this site This is just some dummy data measured in single dollar values. I hope nobody's excited about earning six dollars But it's an example to show you without having to violate anybody's privacy on the sites that I'm managing Direct typing you've got the green line there. So that's if somebody Gets your URL goes directly to the site types it right into the browser Depending on the different types of marketing campaigns that you're doing you would expect different movements in these lines So if you've just done a mailing campaign where you've sent a piece of actual physical mail To your target clients you would expect to see a bump in direct typing Coming into your website if that campaign was successful if you just did push with some content somebody out here was talking about calls to action so content marketing and You've got that content to rank in Google Ranking is great, but if you've got no traffic coming in off of that it doesn't matter So you would expect to see some movement in these organic search referrals and this particular graph is measuring goal completion So if we get a hundred people to come to the website because they found some content in Google and they don't do anything Those hundred people are worth exactly zero to that business. We got to have people actually doing something So some common goals Most of you guys we got a few examples of business models I think just about everybody fits into one of these five categories here So real quick does anybody have a business model that they're working that doesn't fit in one of these No, all right So we're gonna connect business models with some goals on the other side e-commerce just shout it out What's the goal of e-commerce? There you go. That's an easy one if you have a subscription business model. What's the goal on the other side? Subscribers membership site Lead generation All right, you guys kind of have where this is going This is where you can get into those different pieces and that multi-tiered funnel that you're putting together Where you have people subscribe to a mailing list and then eventually you're gonna sell them a product or service I think it was automotive equipment or was that right engines? so you may have social media followers and Subscribers on mailing lists, but ultimately you want to get them over to something where they're buying a product or service And you can do some backwards math to be able to figure out how much is one more subscriber on my mailing list worth This connects goals to key performance indicators to a return on investment one of the things that we always get asked for those of us that are Digital marketing professionals is how can you demonstrate the return on my investment here?  And in order to do that you've got to work out. What is the value of another social media follower? if that's what we're doing what is the value of another email subscriber and it's a rough estimate and it helps you to determine How good of a job you're doing connecting with your ideal audience in some of the other sessions here? You've heard people talk about speaking to your ideal audience The better you do at speaking to that exact audience the lower your cost will be per conversion And the higher your profits will be per conversion So by measuring those things down to the per conversion level You can see those last thousand people that we brought into our email list when we sent them out that campaign And they only converted at 10% and normally we've been converting at 30% Those last thousand people that we just brought in are not our ideal customers How can we tweak that campaign to speak to our ideal customers? so From goals being sales subscriptions memberships leads and influence We can get The key performance indicator e-commerce is a little bit easier for measuring some of these things out because the transaction happens right on the site Not everybody has as easy a time as measuring these things e-commerce has its own set of challenges Measuring the performance of their campaigns is not one of those. That's a lot easier for them Subscribers members Subscribers calls emails for leads depends on what type of leads those are coming in I was speaking with somebody out in the hall about using call tracking So using that data to be able to capture how many leads you have coming in and then how many of those leads actually convert Depending on where they're coming from With that key performance indicator, you can then calculate an ROI with sales. You can go directly to money Ecommerce having it a little bit easier there subscribers sales through messaging so if you have a thousand people that are subscribed to your mailing list and you send them a Message about a sponsor's product or an affiliate link or something of that nature That's where you're going to capitalize on that audience or a message about an event that you're having or however You're selling something to that Mailing list over time as your mailing list grows you can measure those conversion rates You can also measure the conversion rates for specific products and be able to determine is that product resonating with my audience based on how likely they are to buy it or Is my audience changing over time based on how they respond to an offer that I've made previously with a different set of my audience With members sales have paid membership dues I Output of sales funnels with subscribers and Sponsorships and ad revenues a lot of businesses yours Maybe you were talking about getting people to come and look at your website that could be a business model that is monetized through sponsorships or ads along the sides So you're actually wanting to optimize for people to click on those ads You want to get them to come to the website and you want to get them to keep coming back But ultimately you want them to click on an ad and go away and that's how you earn money And I don't know if that's specifically yours, but you're not in your head. So I'm gonna go along with it I'm right close. Okay Yeah, a lot of times it's a good idea to layer multiple different business models So you may have one business model where you're getting people to view and click on ads But then you have another piece where you get them to subscribe to your email list And you make different offers through that email list. So you have multiple pieces that create a virtuous cycle So here's how we can calculate the ROI of Various KPI I'm having fun with these letters everybody before you walked into this room. Were you familiar with KPI? All right, anybody still at this point lost and doesn't know what I'm talking about with KPI All right, I was just about to say if anybody's embarrassed. I'm gonna explain it anyway All right, so KPI is key performance indicators These are the numbers that we can actually measure in order to get an idea of whether or not our business is succeeding at the objectives that we want ROI is return on investment So if somebody comes to you with a marketing campaign and says hey, you give me a thousand dollars I'm gonna do this marketing thing and I'm gonna get you sales on the other side You want to see for that thousand dollars that you spent on advertising you got five thousand dollars that came in and sales You subtract your costs. You're still ahead. Hopefully depends on your margins. We're not going to get into all that math but if you need help with this talk with an accountant and They'll help break down some of these numbers for you And then KPI is where you can measure things like subscribers to an email list that are not directly related to a revenue number So if we have a profit from sales that e-commerce business model That's a direct relationship Whatever profit you got from that sale. That's your return on investment email subscribers Multiplied by a conversion rate So if only 10% of your email subscribers buy a thing and you have a hundred email subscribers, you can expect to sell 10 things Multiplied by the profit for each of those things that you sell if you make a hundred dollars on each of the things that you sell and you sell 10 of them you made a thousand bucks by sending out an email not bad for clicking the send button Right, but you had a lot of work to build that email list Members lifetime average lifetime value.  So you got to have an idea of how long are people going to stay on your Membership site as we get further down. We've got some lifetime value kind of numbers as well. So Subscribing to your email list if you have an educational bend to your site You may expect that within three years somebody is going to go from being Novice at whatever it is that you're teaching them to be an expert and move out of your mailing list because they already learned everything That you have to share that might be the lifetime value of somebody being on your email subscription list You can use some of these numbers to be able to work backwards and figure out how much can I afford to pay For an ad to get a new person to get a new subscriber to get more visitors to my site so I wanted to make this a little bit more concrete and Lay out a little mathematical problem here to explain it to you So we have a course that sells for $150 10% of the people that receive the email will buy that course 50% of the social followers become email subscribers and 1% of the website visitors become email subscribers So that math then works out that each and every sale brings in $100 in profit We can expect to get $10 in profit from each person that subscribes to our email list So if it costs us less than $10 to get a new email subscriber We want to keep doing that if it costs more than $10 to get a new email subscriber. We stop doing that $5 expected profit for each social follower and $0.10 expected profit for each new visitor to the website So if you're only making $0.10 for each new visitor to the website and you can do some SEO content and bring in another Thousand visitors to your website. I Didn't do the math in advance and I should have backed myself into a corner there $0.10 times a thousand anybody real quick Want to throw out the number a hundred bucks? All right, so you can spend a hundred bucks on that piece of content Thank you. Yes standing in front of an audience math becomes difficult Technical challenges so Google estimates that it blacklist 10,000 websites daily I heard another talk that was this morning about WooCommerce security and they were talking about how by showing the little Lock in the top of the browser that this site is not secure that has a significant impact on conversion rates for e-commerce websites Well, imagine when it shows up in Google search results, and it says right underneath it this site is not Secure and then if that message sticks around for any length of time Google says okay, you guys aren't a serious business anymore We're just going to take you out of Google and completely They're pulling 10,000 sites a day because security is not being addressed properly So you can avoid that by having strong passwords doing backups. We all know this right back up your site Avoid excessive customizations What was the number from the trivia yesterday? 55,000 or 65,000 plugins are available on WordPress Some ridiculous number like that I think all of us that build WordPress websites and manage them for other people have probably seen folks that try to install all of them That's a really good way to end up with problems on your website just because there is a plugin doesn't mean it needs to be installed Use strong passwords. This may surprise you but in 2018 only Six or eight months ago. I got contacted by a client that said hey my website's down. It's been hacked What's going on? I said hey, give me a login information. I'll take a look they call it out to me the login password was P-A-S-S-W-O-R-D 123 and I said I found the problem So that's just 2018 I didn't think that I still had to say this but we do Password is not a valid password Use strong passwords If you don't know what that is Google it There are countless articles written about defining strong passwords. Do not share accounts I run into this still a lot where you have one account and everybody in the organization uses the same login everybody doesn't have to be an admin and Do install updates I grabbed this screenshot show hands anybody seen a number larger than 22 updates that needed to be done A few of them. All right. Yeah Let's say for example one person is the master of all accounts, but you wouldn't want to give someone administrative Access to one of the accounts on a list of five for the company so the company has five sides But you want them to go to one only they can't have access to the others. Okay I guess Are you running WordPress multi-site? Yeah, so the question was asking about being able to give access to only one site and Immediately I was thinking you must be running WordPress multi-site because if you had five separate installations of WordPress This wouldn't even really come up as a question because they'd each have separate users It has been a lot of years since I have set up a WordPress multi-site site So I don't know if things have changed But I presume that you can set an admin for an individual WordPress multi-site. I'm getting a nod in the back So it sounds like I'm right Yeah, yeah, so super user gets access to everything within the multi-site. Yeah All right, so Quick show of hands who here has a WordPress website that is not backed up We'll admit it All right, there's a couple people that That's the equipment. Okay. This is an important one. Thank you for reminding me If your website is backed up and you do not know how to restore your website from the backup Your website is not backed up now. Who wants to raise their hand? All right, we got a few more so Z net ZD net did a survey and this is not specific to WordPress websites, but 39% of us participants surveyed never back up their work Given that that's never back up their work on their computer and then we're talking about WordPress it probably is similar And since only three people in the room were willing to raise their hand. There's a few liars here All right, where can you find support This is what you have to know to be a WordPress developer probably a few more things but show of hands Who knows all the things on the board there? All right Not knows the words knows how to do those things Okay, so about a third of the room not bad for a word camp conference So if you don't know these things you're probably going to have questions about at least these or probably a lot more things as well Meetups conferences and the internet are good places to go look for help I gave you a little short list of places to start your WordPress dashboard has an event section and it lists things that are on the Meetup sites right there in your dashboard So you can recognize those the WordPress help desk that I do gets a ton of people that said Oh, I was just working on my website and I noticed this event. It's right around the corner I signed up so that's a great place to start from there. You can go to meet up directly because The dashboard only pulls in the ones that are official WordPress Meetup events and there are a lot of unofficial WordPress meetup events so go to meetup.com type in WordPress see what's in your area Word camp. I think everybody here has heard of that before I Make dot WordPress dot org This is a great place to figure out the people that are making WordPress What different groups there are that are doing that and how You can connect with them Show of hands who here knows before I'm saying it right now That there is a group of people that are actually building lesson plans for you to be able to teach WordPress That are part of the contributor group for WordPress One person. All right, so that's news for everyone There are a variety of support channels There's One of my favorites the next one here codex dot wordpress dot org anybody been to that Few more people have been to that so that's kind of like the It can be It can definitely be confusing if you're completely new to WordPress the codex can definitely be confusing however, if you are a Developer trying to learn how to create plugins and themes and such that's a great place to go One of my favorite things in the codex that I regularly send people to is the article on child themes As you start building out your website and you're trying to figure out what is a child theme? How does this work the codex has a wonderful resource on that and it walks you through the manual process of creating a child theme I look at it the same way that my statistics professor in college looked at matrix algebra They felt that you should probably do this once by hand in order to appreciate what the calculator is doing and so I always recommend to folks to go and build a Child theme once by hand in order to appreciate what the Plug-in that you can click one button and it creates your child theme for you what it's actually doing Now the reason for that is that as you continue to build things with your child theme You're going to want to know where that code is supposed to go What files are supposed to be where and by having done it once manually you'll understand that better That's a bit of a tangent, but bottom line go take a look at make.wordpress.org take a look at codex.wordpress.org See what resources are available there if it if only because you'll be able to know what to come back to And then wordpress.tv, which is where that video is going And what are you going to do with this information? I mentioned having some paper out or some sort of note taking device Everybody that's been to conferences before knows that this happens all the time You come to an event you spend all day learning from people You leave here super jazzed and excited to do all the things that you just learned about Two days later you're busy with work and you don't have time for this And all of that stuff that you are super excited about nothing happens This talk is not going to be one of those If you make an accountability appointment with a person to whom you've committed The likelihood of you completing that task goes up to 95 So you're almost certainly going to get something done if you commit to doing it Tell someone to do it that you're going to do it and make an appointment to follow up Here's what I want you to do for your accountability partner with that note taking device Now that you know all of this information that I just shared with you What task will you be completing? Make sure it's measurable and realistic When will this be done? Set a specific date not a week from now or well a week from now you could actually get the date But sometime within the next six months is not specific The end of May that's specific How do you want me to follow up with you? I'm going to give you my contact information. You're welcome to reach out to me I will personally be your accountability partner. Let me know how you want me to follow up with you If you don't want me to do it contact your friend The keynote speaker if you guys were here for that mentioned having a buddy that's going to call you out on your BS This is a great opportunity to use that buddy And if you need it, there's my email address at the top Shoot me a message. Let me know what to ask you about what day to do it I will put something in my calendar. I will follow up with you about that I will not sell you anything And those are the things that I do if you have any questions No questions We covered everything thoroughly Oh, I saw a hand start to go up Where do they live? Yeah, the slides live on uh Oh, what's it slide share on linkedin. Yep, and uh Oh, it's not all on here My first name is frank middle initial c last name jones So if you search slide share frank c jones You'll find it directly So Click funnels is a cool platform. It gives you a whizzy wig. Uh, what you see is what you get easy way to build those things However, uh, you can also build those things with a variety of page builders Elementor, I know is talked about here. I know that thrive themes. I've used many times before Wp bakery several folks have talked about here and that's just three off the top of my head Essentially what Lead pages and services like that are doing is creating a specific type of page called a squeeze page And all that you need to do within wordpress is Create a blank page that doesn't have your header or your footer and then build the rest of that page around there There's tools within wordpress that allow you to do that without having to pay that ongoing monthly fee So it depends on whether you need the ease of use Or the lower cost, but you can solve the problem in multiple ways On wordpress any of the page builders will allow you to do that Elementor was one of the ones that I mentioned thrive themes Wp bakery anybody else know a Divi Divi, yeah Yeah, squeeze page is a particular type of landing page where essentially people have two choices They can either do what it is that you're asking them to do the call to action or they can leave They can't get lost in the blog or link out to your social media channels and never come back from facebook They can either do what it is that you're asking them to do buy the product subscribe for the email list Whatever or they can click their back button go do something else So you're squeezing them to do something. Yes I'm sorry So Is this only supposed to be about facebook or anything else? So the way that this connects with facebook is that you might have followers that are paying attention to your business on facebook That then come over to your website and interact with your business in some way But they could come from anywhere so it could be more than just facebook All right So I have been working in conversion rate optimization So that's me personally working with a variety of clients with that with opsis. I'm making the transition away from being frank that does work and Become a business that has a team of people that solves a collection of problems So opsis is focusing on wordpress management and building simple wordpress websites As a way to start having a conversation with clients and move into more advanced marketing services Yoast is the one that I use on most of my sites Sorry, I keep forgetting to repeat it. Uh, the question was is yoast Uh favored Framework or our others preferred Given that yoast can slow things down a little bit So The first piece I use yoast on most of my sites that being said I am also Tinkering with rank math is one that I have on one of my sites that I'm exploring with right now Just to see how that works out I the green light system. I also organized the rally SEO meetup group Um, so I use a variety of tools for search engine optimization that go beyond just yoast as a starter tool It's really easy to sit somebody down and say make all the lights green So that's a huge feature for beginners but Aside from editing uh meta titles and descriptions. I don't use most of the other features that are baked into yoast As far as the optimization piece goes if you properly optimize wordpress, uh, the plugins don't bloat it as much um I run uh my sites on my own vps servers that are optimized the way that I want them and uh I can make them load fairly quickly But if you're Using a five or ten dollar a month hosting provider, you're going to run into some challenges there anyway Uh, and I always like to recommend the right solution for the right stage of business If you're new and you're just beginning you don't need to deal with any of those optimization things that i'm talking about Just stick yoast in there make the lights green and prove your business model once you've moved beyond that Then we can optimize further with other things Anybody else? Yes, sir What ab testing do you use to see what works? What's working for conversions? So there are a variety of ab testing What ab testing tools do I use I With the clients that i've worked with i've used a few different ab testing tools oftentimes Thrive themes has some split testing tools that are plugins That i've used with them A couple of others that the names aren't coming to mind right now, but Most of the time we're dealing with what i like to refer to as business level statistics Not academic level statistics If you're an academic and you're looking at the math that we're doing here You're going to just laugh because we don't have anywhere near statistical relevance But if I run an ad campaign and i've got two different facebook ads They've both been shown to a hundred people One of them's gotten me 50 clicks. The other one's gotten me two clicks I don't need any software to tell me to turn off the one that got me two clicks And keep going with the one that got me 50 clicks right presuming clicks are the things i'm after as opposed to conversions If we are measuring conversions Just to twist that example a little bit if those two clicks both turned into a sale And the 50 people that clicked on the ad nobody bought anything I'm actually going to turn off the one that got 50 clicks and stick with the one that got two clicks that actually bought something Does that make sense? So it's a matter a lot of it is very basic level math that you don't need software to do the heavy lifting You just need to set up an experiment where you have test a and test b and then let it run to where you have At least 50 or 100 or so Uh, it depends on your market for some people 100 people might actually take weeks to get there for other people It might be hours So There's a lot of variables there. Does that make sense? Yeah, that's sufficiently answered. Okay Any other questions? All right, please before you're done Do we'd love your feedback?


Good morning everybody. Today, we are going to discuss functions, but to begin with I will complete the discussion that we had left yesterday on the iteration. So, what I propose to do is to complete the discussion on iterative solutions. Basically, revisit the problem of finding roots of a given function and look at different ways of prescribing iteration. We will then describe the notion of functions, the need for such functions, the way we define functions and the way we use these functions. Workshop projects or workshop activities is an important aspect on which there seems to be a lot of confusion. So, this is what we had begun discussing yesterday, the Newton-Raphson method to find the roots of a function that is find out x such that f of x is 0. And we had said that the method will work if f of x and its derivative f dash x can be easily calculated and a good initial guess is available. As an example, we decided to find the square root of k. Incidentally, I had just said use f x is equal to x square minus k. While you and I can understand that easily some of our students might have problem in saying where does this x square minus k appear from. So, I have added a small explanation as you can see on the right corner. I say let x is equal to under root of k, then x square is equal to k and x square minus k is 0. Essentially, this is how we arrive at the function f of x is equal to x square minus k. And of course, f dash x is equal to 2 x is easily derived from this. In any case, we observe that f x and f dash x can indeed be calculated easily. Only few arithmetic operations are required and we can start with an initial guess x 0 equal to 1 which in this particular case it always works, it can be proved. So, we looked at the method that we will follow. Essentially, the iterative method of determining the root will begin with some initial guess which we call let us say ith value of x where i is equal to 0 or initial guess. And our job is to keep finding a better value of x. Naturally, if this is the nature of the curve and it crosses x axis at this point, then clearly this is the root of the equation. So, we want to determine this value of x. Now, this value of x will have to be approached iteratively starting with this value. And what we are looking at is how to tell our students how we can build an iterative method to do this job. So, we observe that we have a point A which is the initial guess, its x coordinate is x i which is our initial guess, its y coordinate is 0. So, we conclude that point A is known. Now, we determine function of f x at this point. Now, this function evaluation will essentially get us the value of the function at this value of x. Let us say we get another point B. The coordinates of B are x of i that is the x coordinate and the y coordinate is nothing but the value of the function. That is why we say point B is x i comma f x i. And we now say it is known. That means it can be computed. So, once we assume an initial value x i, we can compute f of x i. And therefore, we can know the position of B.  Now, tangent at point B which is drawn on the function, it will intercept the x axis at a certain point. Let us say this is the intercept. Now, obviously you will notice that this intercept crosses x axis at this point which is clearly closer to the root. Obviously, because we are approximating the slope of this function by this tangent and as the function approaches the x axis, so will this tangent. So, that is why we can see that if we can use this as the next iteration point, then we have made an improvement over the original case. And successively, we would like to find such points by repeating the process. Anyway, to complete the discussion of this particular computation, we have calculated a coordinates of a which are simply x i minus x i comma 0, x i being the initial guess. We have computed the coordinates of point B by using the function evaluation as shown here. Then, we say we approximate f by the tangent c which is an intercept on x axis whose coordinates, let us say are designated as x i plus 1 comma 0. Our job is to determine what is the value of x i plus 1. It is for this purpose that we denote this as point c and show that the coordinates of c can be calculated by using a formulation of this kind namely f dash x is essentially the slope of this tangent which is a b by a c. So, we say this slope the a b by a c can be computed based on the coordinates that we now know. So, a b is simply the value of function f x i, a c is the difference between x i plus 1 and x i. So, the ratio of f x i divided by this is actually the derivative. Since the derivative is computed independently, we can by implication find out the value of x i plus 1. In this case, it simply amounts to x i minus f of x i divided by f dash of x. So, now you can see that I can set up an iterative computation in motion by starting with an initial guess x i, calculating f of x i and f dash of x i at that x is equal to x i using that calculate another value for x and then take that value as x as initial guess and then continue.  So, we conclude that starting with x 0 equal to 1, we can compute x 1 then x 2 and so on. Each successive value of x i will be closer to the root. We also note that we can get as close to square root k as required by carrying out these iterations many times. Suppose I carry out these iterations a million times, 2 million times, are we sure that we will get a value of x for which f of x is exactly 0? Well that is doubtful and that is because the computations are being done using floating point and errors in floating point computations were visited by us briefly which tells us that we may become very close to 0, but we may never get exact same. In fact, that is something that we should emphasize to our students right from the beginning that computational solutions to such analytical problems will yield approximate results which may be very close to the exact result, but you may never get the exact result as you may analytically get. Additionally, there could be a problem of stability of our iterative process, but then that is the topic for advanced discussions in numerical analysis, we will skip that. So, this in a nutshell is the method of finding out square root of k. Notice that the notation that we have used here x i plus 1 x i etcetera etcetera is to indicate successive iterations. In a computer program we do not know how do we describe x 0, x 1, x 2 these are not different variables. We can use only one variable and therefore it is important to tell our students that we start with one value and we evaluate successive values. So, notice that we have used only one term here successive values of x i and then we say that in our program we will simply use a variable x which represents the current value of x that we consider. Consequently, our program segment which will implement this I call it a segment because I have done away with the mandatory lines which always appear at the beginning of our program like hash include and int function whatever whatever int main etcetera etcetera. So, calculating square root of a number k start with a variable called k defined as floating point value because that is the value whose square root you want to find out. I input that value then I define float x i equal to 1. Notice that i is only an honorific attachment to x it has no significance. Indeed when I write x i like this in a computer program the two characters together simply define a male like any other name a b c alpha beta whatever one. So, x i is merely one name represents one variable which is a floating point variable and we initialize that variable to a value 1. Incidentally, we may use such an opportunity to introduce a concept namely initialization during declaration and then explain to the students that ordinarily I could have said float x i semicolon followed by x i equal to 1. Instead I can combine the two and provide an initial value to the variables which I declare during the definition of those variables themselves. We now proceed ahead we consider this to be an initial guess we comment that it is known to work the iteration itself which is set up is extremely simple. So, look at what we are doing for int i equal to 0 i less than 10 i plus plus I write a comment saying I am doing 10 iterations what am I doing 10 iterations for I use the present value of x i to calculate x i plus k by x i divided by 2. Remember this is the formula that we had derived for finding out the next better value of x. Consequently we assign this value the value resulting from the evaluation of this expression to our x i itself. So, we begin with some x i we modified it here when this square this brass is encountered the computer will go back here and re-e-trade and therefore it will successively use the new values of x i that we so compute. At the end of the 10 iterations whatever is the value of x i we will print it out. So, we notice two things one the program is pretty simple to write once we have understood that derivation and the identification of the block of statements which need to be executed iterative. Having done that we expect that in 10 iterations we should get close enough value, but can we be sure can we not write something which will check whether we have reached very close or not after all the root may still be further away. Essentially what should we do then we should examine whether we have reached very near the root or not. How can we do that? Let us look at a piece of paper to understand that. So, effectively so this is the point with which we started. Now what we are seeing is by using the method of the successive approximations like this I may come to this point then I will come to this point etc etc but after 10 iterations how far away I am from this particular point is not very well known. I may be somewhere here or I may be somewhere here only. You will agree that if this is the 10th iteration value that I get it will not be close enough to the root. If this is the value I get I will be closer. Strictly speaking how do I define the closeness of my final value with the root? That depends upon the difference between my final value and the actual value. I do not know the actual value so how can I compare? Well I can compare not the value of x with anything because the final thing is not known but I can compare the value of f of x. Notice that as I approach the root from this side the function is approaching the root from this side. So, if I calculate the value of the function at my final value of x at this point it will be this value. At this point it will be this value. Notice that at the root the function value should be 0 and therefore what I can do is I can find out the value of the function at the value of x that I have and see how close it is at or near 0. So essentially I have to compare the difference between f of x and 0. f of x should be ideally 0 but it will not be exactly 0 so how close it is is what I want to compare. Since in general I may approach this either from the positive side or from the negative side I should actually calculate the mod of this difference. Since I know the difference will not be exactly 0 I can put an error limit and thereby conclude that my calculation of the root is within this error specification. So, let us go back to our slides. So, we use this to calculate the root in a slightly different fashion. Here is another way. Here I start with the definition of x i and k as earlier float x i comma k. I now say c in k and then instead of initializing the first value of x i I do it inside the for loop. So, notice what I have said for start with x i equal to 1. So, I know the initial value but when I use such things in for loop the iteration condition as well as the increment has to be prescribed within the for statement itself. You will see that I am able to do all of this within a single for statement. So, let us say what am I trying to do here? I start with x i equal to 1 same equal this is the first part of the specification. So, I say initial guess known to work. After this semicolon I am supposed to write the condition which must be met for which I will continue iteration. The moment that condition is false I am supposed to quit iteration. Earlier we had written the condition in terms of count because we are doing 10 iterations. Now the condition that is being put is different. Look at what we are saying x i into x i minus k is greater than 0.001 or notice this is the or symbol or k minus x i into x i is greater than 0.001. Why we are writing these two conditions and that is because x i square minus k may be positive or negative. So, what we are saying is either this or k minus x i square basically we are calculating modulus of this particular expression. If this is greater than 0.001 what does it mean that the function value at the calculated point x is away from 0 by this much margin. What I am trying to say is as long as you are that much away from the root please keep reiterating. So, notice we now do not care how many iterations it takes 10, 15, 20, 2000, 200,000 whatever. All that we are saying is for every value of x calculate the difference between k and x i square. Ideally both should be same that is when we would have found out the correct root as x i. If they are different then we are saying as long as they are different probably more than 0.001 please continue iteration. So notice that in the first statement the initial value is given here the condition for continuing iteration is given here and after the iteration I am supposed to calculate the new value of x with which I want to continue. So, curiously in the third part of the four specification after this semicolon where I will ordinarily say count equal to count plus 1 or i plus plus or whatever instead I put this statement x i is equal to x i plus k by x i divided by 2 semicolon. This is the power of the generalized for loop namely the last part of the four specification need not be a mundane increment to a single variable. Notice that when we describe the structure of the for statement we said this could be any group of actions which must result hopefully into modification of one of the loop variables otherwise the loop will become infinite. So, inside the for loop we are beginning with the specification of initialization we say it is an initial guess known to work then we prescribe a condition for continuation of the iteration based on what we want to finally achieve that is until error in the square is at most 0.00 and if the iteration is executed what do I want to do next I want to continue calculating with a new value of x i which instead of calculating in the body of the loop I am specifying here as part of the for statement itself x i is equal to x i plus k by x i whole thing divided by 2. Having done this I notice that I do not need a body of the for loop at all because there is nothing else to be done curiously this is a complete and correct for statement initial value condition to be checked for continuing with the iteration and at the end of iteration what is to be done. So, actually what the for statement will do because of this semicolon notice that there is no brace here what the for statement will do is it will start with x i equal to 1 it will evaluate this condition initially obviously it will meet this condition the value difference will be greater than 0.001. So, it will say let me execute the body of for remember the w w w which we had denoted the body of for statement it will come out of this to examine where is the body it will find the body is null it will execute that null body means it will do nothing and will go to carry out the increment that we have prescribed in increment we are actually calculating the next value of x i after calculating this increment as per the specification of the for loop execution this condition will be again evaluated if this is true again I will go out see null body execute nothing come back do this increment again check the condition. So, I am specifying the entire iteration as a single for statement is actually a beautiful construct people might find it confusing you might therefore want to ask your students to rewrite this in the conventional form by putting this condition inside but by putting this increment or computation outside and by continuing may be detailed now when you do not want to iterate a fixed number of times and still want to use the for statement for forcing iterations this probably is the best way of describing thing after doing that you simply output the value of x i you will notice however that for statement which we said is meant primarily to execute a body of statements for a fixed number of times does not appear to be very logically appropriate for this type of activity iterative activity where our iterations are not bound by a count they are not to be executed for a defined number of times but they are to be executed while a certain condition is true as long as the condition is true I was to keep iterating this there is another way still another way of specifying iteration in C before that we will just describe the special ways of using the for loop whatever I just described is discussed here for x x x semicolon y y y semicolon z z z the body is w w w this was the specification of the for statement we saw yesterday in the alternate that we just notice the computations required for each iteration are all specified as part of the specification of for statement itself thus the body of statements w w w is missing because it is not required incidentally you may want to introduce another variation of this structure itself where we simply say for nothing semicolon nothing semicolon nothing and then w w w this curiously specifies an infinite iteration and the loop must be broken by some condition within w w w since we do not know how to break out of a for loop except when the for determines that a condition is over we will have to later on see how can we do that neatly indeed there is a break statement which we shall discuss later which can permit us to come out of the loop from within the body of the w w w statements that we see this is the other way that I mentioned I say float k I take as input the value of k I define my iterative variable x i and say float x i is equal to 1 now look at the iteration that I am describing now I am not using for I am saying while x i square minus k is greater than this or k minus this is greater than point zero zero one do the following iteratively what is the following x i equal to x i plus k by x i slash two indeed this is a far better way of specifying iteration when the iteration control is based on a condition to be satisfied rather than any count this is intuitively clear to any reader while this condition is true execute the body as many times as required till the condition remains true when I come out of this iteration I will come out only when the error is less than zero point zero zero one and at that point I can print the existing value of x i so this is a very neat way of setting up an iteration which is based on checking a condition which is not necessarily a counting condition it is useful to one of our students that extra care must be taken to ensure that sometimes this condition will become false because if the condition never becomes false it always remains true then I will have an infinite iteration that means our Dumbo computer will never come out of this iteration in this particular case we are reasonably sure that our algorithm will find out the root within this error range and therefore this algorithm is definitely workable this is a formal definition of the wild statement wild condition loop body so notice that loop body is nothing but w w w that we use in the description of the far structure so what does it do the computer first checks the condition if the condition is true then executes the loop body and keeps doing the same so repeat this simple specification iterative specific check the condition if condition is true execute body again go back check the condition execute the body check the condition execute the moment the condition becomes false comes out and execute another statement following the loop body if the loop body is a single statement then we need not use brasses this is incidentally true for false statement also is also true for if statement incidentally as teachers we should emphasize that putting brasses is recommended always why because later on if we modify the program and we decide that in a certain block which was originally only one statement we need to add more statements then we may forget to put brass there and the entire meaning of the program may change so since we may do such forgetfulness we should put the brasses right at the beginning this is a good practice finally a brief word on comparison between for and why if there is a control variable with initial value update rule and whose value distinctly defines each loop iteration such as a counter use for also if loop executes a fixed number of times although there may not be a variable used in computation but it executes a fixed number of time like execute ten times etc. preferable to use for in all other cases it is preferable to use why there is a third construct in C for prescribing iteration and that is called repeat until the only difference between for and while and repeat is that in both for and while the condition that we have prescribed is checked before even the first execution of the loop body is carried out that means it is possible that if the condition is false at the beginning the loop body may not be executed even once in case of a repeat statement where we write the word repeat then we write the block of actions to be iterated and then finally we say until such and such condition the condition is checked at the end of the loop and if it is false we come out with this background we now proceed to discuss the notion of functions consider that what we found out the root of a equation just now consider that we want to find out the root of a more general function let us take a quadratic or it could be a polynomial or any other function we consider as an example a quadratic function a x square plus b x plus c in this case f dash is equal to 2 x plus b now if I want to redo or rewrite my program of Newton Raphson method to calculate the root of this equation then I will have to make changes in my program at places wherever I was doing calculation of f x or f dash x as a matter of fact you will notice that in this example we are simplified the ratio of f x and f dash x and we had actually got a uncanny formulation which was neither f x nor f dash x let me go back a few slides and tell you what we are done there look at it this way we were calculating x i is equal to x i plus k by x i whole thing divided by 2 where did this come from is this the definition of f of x no is this the definition of f dash x no what we did is in the Newton Raphson method we found out the formula for x i plus 1 to be computed from x i using f x and f dash x of course and then simplified it as a result the function or its derivative evaluation does not occur explicitly here at all now suppose we go back to the slide that we were discussing namely the function definition suppose I want to use my program but for calculating root of a different function as I said in this case a quadratic a x square plus b x plus c or 2 x plus a b which is f dash x there is no easy way by which I can simply replace some statements in my program and fit the requirement of this quadratic function in the Newton Raphson method so we say that it would be nice if we had separate blocks of instructions to calculate these for different values of x so whatever is the function and its derivative if I had written a code to calculate the value of the function and code code meaning program instructions to calculate the value of the derivative at a separate place then it would be very easy for me to replace those statements by some other statements representing another function this is precisely the purpose of a function in C which represents such a separate block what a function does is that it takes one or more parameters and returns a single value of a specified type that is the objective of a function here are examples of functions the examples represent exactly the same functions that we are considering namely a quadratic equation and its derivative so here I have said float my function in bracket float a float b float c float x then I have said float value then I have said value is equal to a into x square plus b x plus c and then I have said return value closing bus let us spend a couple of minutes in discussing what this is it appears to be almost a complete program which it is in fact it has a declaration for a variable called value it has computations in the form of this expression however there is no input statement so there is no way the value equal to this expression can be evaluated because we do not know where are the values of a or x or b or c are coming that is the objective of putting these descriptions within the function itself inside brackets notice that this resembles very much like a mathematical function that we are familiar with in this case my function is the name of the function that I am giving float a comma float b comma float c comma float x are called four parameters with which I will call this function why there are four parameters because to evaluate the quadratic I require values of a b c and a b and c finally it says return value that means we sort of understand that this function will execute as a standalone entity somebody at the beginning must give this function values of parameters a b c x and at the end of computations this function will give that value to somebody who is that somebody will come to that but effectively we conclude that function appears to be a standalone program which cannot be executed just like that on its own but somebody else will say I want to execute this function whenever that somebody wants to execute this function he or she must give this function appropriate values of the parameters as described here when function computations are over the computed value of the return value will be returned to that somebody who called me to execute this function this is the way I can write as many functions as I wish I have written here float my function and float my derivative because for this particular problem I need the calculation of the function value and the calculation of the derivative notice that in the second function called my derivative I have only three parameters that is because the f dash x in the case of a quadratic requires only values of a and b and of course the value of x at which the derivative needs to be computed here the computation is similar but simple I describe float value again value is equal to 2 a x plus b and then I say return value so this second function appears to behave very similar to the first function except that it is doing some different computation some questions having said float y value here why am I saying float value again having said float a float b float c here why am I again saying float a float b or even float x for that the correct answer is and this must be communicated to the students very early that each function is to be regarded as a separate program and a separate program means that program does not know the existence of other program consequently when we write these functions if I write ten functions although I may use same names in fact with similar meanings the name used in one function has absolutely nothing to do with the name used in another function so these functions are completely independent of each other in terms of the computations that they do in terms of the variable names that they use in terms of therefore the memory locations which they indeed when our c dumbo looks at these functions it will actually compile these and will create separate memory locations for this a for this x for this b for this c so you will see when you save this float a float b float c float x etcetera are not only therefore definition of definitions of the parameters but it effectively also tells c that please reserve space for a b c and x even in the main program I am using the same names those names will have different locations these names will have different locations ordinary much later in the course when we describe the notion of passing parameters by address or by reference at that time we will clarify that situation could be slightly different but ordinarily a function definition is used in c to isolate a certain part of the computation and such isolation is accompanied by the corresponding isolation of all the variables that are used in that function so I repeat while I might be using a x b c etcetera etcetera in the main program from which I propose to call this function these names a b x and c are completely independent of any similar names that I might have used here not only there in my main program but even in any other function as can be seen so these two functions in fact are completely independent bodies of code having said this we will now look at how functions are to be used and what are the rules of invocation of these functions first the syntax notice that we have not used the word syntax so far if this is the style you wish to adopt in your teaching then it is good to formally introduce the word syntax somewhere and say that syntax means the exact grammatical rules using which you much must write various instructions or statements in the c program so whenever I want to write the function definition then I must know the grammar rules or syntax rules and that is why I am defining syntax of defining the function in my function float a comma something comma something the first word here int tells me that type of the value which will be returned notice we said function will receive some parameters calculate some return value calculate some value and return it that value itself could be integer could be float later on as we shall see it could be of some other permissible data types also how do we let the see the computer know what type of value will be returned that is prescribed in the first word you will recall that yesterday a friend of ours had asked the question that wide something is often used wide main so what is the purpose of wide the purpose is that if I have a function which does not return any value and we shall see why such functions could be returned we may simply say wide here in which case the return statement will not exist inside exist inside that function so here I am saying int my function float something something the first word there is that type of the value which will be returned incidentally I should not use the word int in the context of the example that we are discussing because the example requires us to calculate a floating point value a real value and return it so this is actually a mistake it should be replaced by float next is the name of the function which we choose appropriately I have said my function deliberately it could be absolutely any name f square root square quadratic polynomial my polynomial whatever what incidentally the naming convention in C permits you to use a very large number of characters to define the name there are rules of format forming names we have not discussed them in this class but these rules are prescribed in every standard textbook and it is part of the C standards in a nutshell the name can be as long as you wish but the first thirty characters of the name must be unique so in a program I can use names with very large number of characters and it is recommended that we use this facility to name our variables and functions etcetera appropriately so the name should reflect the meaning here I am saying my function therefore I called it my function so to recapitulate the first word describes the type of return value the second word describes the name of the function this is followed by a set of parenthesis in which a series of parameters are listed so this is followed by one or more parameters whose values will come from the calling instruction what is the calling instruction we do not know that yet but we understand that this function will be in hold by someone for some computation whosoever that someone is will be supplying the values the parameters is what we are saying then there are some computations in the body of the function and finally there is a statement return value this says what value is to be sent back in general it can be an expression so instead of value I can say a into x divided by y multiplied by z plus something whatever whatever it can be any complex expression that see programming language permits the expression will be evaluated based on the values of various entities involved in that expression at that point in time and whatever is the single resulting value that will be returned return to whom it will be returned to whosoever called this function for evaluating the value of the function the point to be noted is that while a function may collect as input to itself multiple values from different parameters as prescribed here it will always return a single value only that is the reason why the single definition of type is adequate in this sense it it works very close to or similar to the mathematical functions so when I when we say y is equal to f of x at x equal to something then it gives you a single value y could be equal to a function of x comma z comma a comma b comma c but we imagine that mathematically it will take all those parameters calculate a single value and return it which is what will be assigned to the left hand side that is precise the purpose the value which is calculated after all this and return is a single value and the type that is defined for the function is that single value here so we again reiterate this return value says what value is to be sent back it can be an expression which is evaluated and the return statement is executed there in our model of computing where does this fit since we are thought of our entire c programming language and the computer which executes c program as a dumbo we can imagine that each such function is to be evaluated by a separate assistant dumbo separate from our main dumbo so anytime a function is invoked within an instruction which is executing who is executing this our dumbo so I have a c program in which I am executing instruction one instruction to instruction three etc suddenly dumbo finds during the execution of fourth instruction that a reference to a function has been made a reference to a function will naturally involve the values of those parameters which are required to calculate the function value at that point in time however whenever a function reference is encountered what Mr. Dumbo does is that he hands over the given parameters to the assistant dumbo and says you calculate this function and come back to the assistant dumbo now takes these input incoming parameter values calculate the function value and returns the same to the main dumbo what does main dumbo do notice that he had temporarily must have suspended the execution of instructions at his end because when he encountered a function he was in the midst of doing some computation so he would have stopped at that point he has given the function evaluation task to assistant dumbo assistant dumbo completes the calculations and after completing the calculation hands over the return value to main dumbo main dumbo now takes that value and uses this value in place of the function reference so whatever was the function reference originally during execution it is now taken out and a single value is put in its place and dumbo calculates the computations or execution of the instructions from that point onwards so this is a reasonably easy and decent way to explain to the students of course in practice there is no main dumbo an assistant dumbo it is the same dumbo or the same computer which is doing all of this but by giving this kind of example we can help our students to mentally separate out the function evaluation from the execution of the main problem how do we invoke a function the function is invoked through a function call so within a program you have to give the function name with appropriate parameters within any expression wherever you require the value of the function in the Newton Raphson method we have the value x i and we calculate next value using this suppose our function was this then we could design our program using the two functions which we have written my function and my derivative why because my function calculates a x square plus b x plus c and my derivative calculates to a x plus b which is nothing but the derivative of f f of x f dash consequently let me go back to slice and show you those functions once again these are the two functions which I have written float my function and float my derivative exactly these definitions float a float b float c float x as parameters this computation followed by a value being written in case of a derivative parameters are a b and x computation is this and at the end the value of the derivative will be calculated and it will be written so the function definitions are complete having defined these functions let us go back to our slide now what we are saying is that in order to implement Newton Raphson method using these functions I simply could use my function and my derivative wherever I need to calculate these functions here is the implementation of Newton Raphson method using function calls notice that the program now says int main as usual float x comma a comma b comma c comma root please remember these a b c x etcetera have nothing to do with a b c x that we used in the definition of the function these are now the variables of our main program for which number would allocate different memory locations to it I will read values of a b and c now the iteration is set up by starting value x is equal to 1 for int i equal to 0 i less than 10 i plus plus remember the first instruction the only difference now I am saying is in the body of the iteration I am saying x is equal to x minus my function divided by my derivative so wherever x minus f of x divided by f dash x was there I am replacing it by a proper call or a reference to the function that I have written it is interesting to very briefly dwell on what happens when this program is executed this is very simple reading is very simple initialization is simple we understand the first statement initially i is 0 since i is less than 10 I will actually go into the body of the execution the body says x is equal to all of this what will dumbo do what will computer do the computer will first ignore the left hand side remember what we said is first evaluate the expression on the right and then find the single value and allocate it to x so the computer goes to the right hand side it notices this is the beginning of an expression first element is x so you will go to the memory find out the current value of x which incidentally will happen to be 1.0 which is the initial guess first time then it sees a minus sign and it sees my function a comma b comma c comma x please note that this is not a multiplication this is not an addition this is not a value this is not a variable so there is no direct way for computer to get this it therefore understands that this is a reference to a function it will now go to that my function using the present values of a b c and x an important point to note is that if that function has been written to accept four parameters in a certain order then the actual values that are supplied to the function must exactly be four in number and must exactly be given in the same order so you will notice a comma b comma c comma x written as parameters computer will take these values which are here in this program at present so whatever the values of a b and c which have been read and the value of x at this moment is one so the input values and the value one will be taken by the computer and it will now go over to my function within the my function using these values it will calculate a return value which will be nothing but the value of a x square plus b x plus c at the given value of x now when the function finishes the computations it will come back with that value what Dumbau will do what the computer will do is it will replace this complete reference by a single value the value could be 2.175 value could be a 0.0124 whatever whatever that will be the value here in exactly the same fashion now the Dumbau will continue computation it has got x minus 2.12145 let us say then it looks here slash so division divided by what another function called my derivative in brackets a comma b comma x compared to exactly what it did earlier it will go to the function my derivative taking with it the values of a b and x will calculate as per the specification in that function called my derivative get a value bring that value back here and replace this reference my derivative a comma b comma x by that value so the simplified expression for Dumbau has now become x is equal to x minus 2.13 divided by 3.12 let us say meaning depends upon what value you have got now the expression is simplified the crux of this is a function reference causes an invocation of the function where the values are taken to the function which are given as parameters and it also causes a return value to come back and replace the entire function reference that we have made in the expression this then is the mechanism by which functions are invoked. We consolidate the invocation rules by revisiting the statement x is equal to x minus my function a comma b comma c comma x divided by my derivative a comma b comma x so when Dumbau encounters my function while evaluating this expression it suspense execution of the program first of all it says temporarily wait I cannot proceed unless I get the value of the function it goes over to the defined function with the available values of the parameters then it calculates the value executing given instructions within that function so it has suspended the execution of main program it has gone over there it has executed the instructions given in the function using the parameters which we have supplied calculating a return value and then it brings the value back here when the execution control comes back to our main program then we replace the reference to the function by the return value and continue evaluation of the remaining expression so it is extremely simple and straight forward as long as we understand that function is a body of code return and kept separately somewhere whenever a reference to the function is made computer is supposed to go there with parameters execute those instructions and come back with a single value and whatever was the reference to the function made in my main program that reference will be replaced by that single value that is how the invocation works a few points to ponder on this issue first we see that the calculations pertaining to our function evaluation have been separated out by writing the function separately perhaps resulting in a better structured or modular program why is this important we again reiterate what we began with suppose I want to calculate the root of some other equation that is we wish to modify the same program to calculate root of another function then it is far easier to replace code only in that part where functions are defined notice that the implementation of the Newton-Raphson method with the name my function and my derivative is generic now if I have a different function then I will take that function and its derivative rewrite the function definitions which I have given replacing them by the right computations but my main program continues to work well if we do not do that we may otherwise have to search our entire code in the main program to find out which lines we have to change if I have to change a function and as we saw the original implementation of Newton-Raphson that we did the value of the function and the value of the derivative was not directly visible in the code that we had written because we had simplified things there in short modular programming or structuring our programs like this where we isolate code which may have to change is an extremely good practice is another useful thing that we are emphasizing to our students when we use this kind of a here is something that a student may ask and if the student does not ask loudly in the class because these their students do not tend to ask questions we have to encourage them to at least think like that and preferably ask questions like so I may as a student now I may say can I use programming code for functions written by others now you have suppose somebody has a very complicated function definition and he has already written a program can I use that program yes of course that is the very idea in fact we can at this stage if such a question is raised and as I said even if the question is not raised we should actually invoke this question and we should say we can even compile those functions separately and link them with our program but we need to include prototype definitions of these functions within the program so that our program understands what I am going to call at any point next question what is a prototype well that is where we stop we will say the notion of prototype shall be introduced when we discuss separately compiled functions later in the course incidentally another point to ponder is we perhaps now understand why we say int main and returns hero in our main program notice I mentioned this in the as an answer to a question but it should perhaps now be related to the fact that our entire program is actually treated as a function by the operating system so when we ask the operating system to execute our program by saying dot slash a dot out that's the command to the operating system so operating system now is the main number the main number says dot slash a dot out and it says ah this user wants to invoke a function called a dot out so he goes to my subdirectory finds that executable code loads it and starts executing it as a function it need not pass any numerical parameters to that function because that's the main program written by some human being so operating system assumes that you would supply all the values as input or something however later on we will notice that whenever operating system invokes a main program as a function it does implicitly pass certain parameters to that in case of c they are called arc c and arc v we shall discuss these at a later stage at this juncture we need not worry about it we can just tell our students that ordinarily the operating system will merely invoke our program as a function whenever we say dot slash a dot out or whenever we basically ask the operating system to execute our program whenever our program terminates the execution the computer doesn't halt because in real life in the labs we have seen that when the program execution completes we simply get a command prompt back dollar who shows us that dollar not our program it is the operating system which shows us that dollar prompt consequently it is reasonable to assume that just as I have understood how to invoke function and get a return value the operating system when it treats my program as a function invokes it and at the completion of the conclusion of that invocation or that completion of execution of that program it shows me again a dollar prompt how does operating system know that my program has finished execution internally my program when executed through dot slash a dot out actually is invoked as a function it completes execution and returns the control to operating system while doing so it may optionally return a value in most cases it is advisable to return an integer value and that is the reason why all main programs which are incidently functions for the operating system as we see are generally written as in to main and generally an integer value is written the convention is if the value 0 is written the operating system assumes that the program executed healthily and concluded its job proper however if we encounter some error and if we wish to inform the operating system that there was a problem we can return some negative value such as minus 2 minus 7 plus 28 these are arbitrary values we must understand what operating system will do with these arbitrary values preferably we should ourselves prepare some kind of error reporting in the while the program is being executed but essentially as far as operating system is concerned it is invoking our main program as a function and taking back a value if the function is supposed to return a value of a specific type so with this I conclude this part of my talk if there are any queries I would like to go over to there is a query from JEC caucus I will go over to JEC caucus now to see what is the query JEC caucus over to you what is the take side of the function over to you I will repeat the question for the benefit of others thank you the question is what is the size of the stack of the function unfortunately that is not a concept which could make sense to first year students at this juncture but for your information the way the functions are invoked the parameters which are passed usually the operating system or even the runtime system of a programming language will use stacks on which you will push the various parameters it is not uncommon that in order to do context switching namely I am keeping my present program in abeyance and then going over to another program after which I have to come back and start executing my program in which case I may push variety of information about my current program also on a stack as far as the function is concerned the function stack is actually could be a growing stack depends on whether I am calling that function just iteratively or recursively if I call it recursively I will require a growing stack if I am calling it iteratively the stack will be limited the exact value or the number of locations in that stack are irrelevant we presume that the operating system will provide as much memory as is required for the function invocation from that stack thank you very much VNIT knuckle has a question let me go over to VNIT knuckle thank you very much the question is that the value of an integer which were defined yesterday I had defined it to be in the range of minus 2 to the power 31 minus 1 and he thinks that it is only in the case of positive integers not in the case of negative integers I notice that there is a similar question from my a view people here this is a question asked by a participant from PSG co-emptor if we declare an integer variable the largest value it holds varies from system to system what is the reason behind this also the question asked by our friend in VNIT knuckle which is is the range correct so let me go over to it again to a paper usually we allocate 32 bits for an integer in fact the exact number of bits allocated actually varies from compiler to compiler so first let me ask the question to our friend from co-emptor why on different systems the values are different the values are different because on some machines particularly smaller machines a integer may be allocated only 16 bytes of space a 16 bits of space here now obviously 16 bits will hold much smaller value than 32 bits in some cases such as large mainframes or supercomputers my integer may be 64 bits in which case I will have a larger value here still in some other cases where multi precision arithmetic is implemented and during the course of workshop when we discuss the arrays I am going to actually discuss a problem where I want to represent let us say 100 digit numbers or even 500 digit numbers these could be artificially done through software so there are variety of ways but as far as the basic data types are concerned yes the data type int and long end could have different definitions on different machines typically however an int is 32 bits now coming back to the question from our friend why is the value 2 to the power 31 minus 1 he thinks it is only in case of positive integers not in other cases actually what happens is there are two ways in which you can represent values let us consider the 32 bit representation the value can range the if I just look at the number of bits the bits can be either all zeros or the bits can be all ones these are two possible combination this will result in a value 0 and this will result in a value 2 to the power 32 minus 1 you can actually confirm it by looking at an 8 bit number if you have an 8 bit number then the smallest value you can represent is 0 and the largest value where you are all 111 and all the 8 bits the value is actually 255 which is nothing but 2 to the power 8 minus 1 so this is strictly speaking the range of values that you can store internally however if we did that we can never represent negative values so the C compilers actually permit us to use a signed value so that is why whenever we say int it is not an unsigned integer value that we are representing but we can represent positive or negative values both how can we do that so what the compiler does is it takes out one bit from this 32 bit and this bit is often treated as a signed bit technically most compilers use a two's complement representation to store negative values without going into those details also you can see that the remaining 31 bits now can have a value largest which is 2 to the power 31 now I want to represent positive and negative values so if I remove this signed bit I will remove this say one value from there so either the largest value is 2 to the power 31 minus 1 positive value and I can say negative largest value is also minus 2 to the power 31 minus 1 if I treat this as 0 to mean plus and 1 to mean minus so this is the simplest exploration that is the reason why the the value range turns out to be like this I do not know if in your syllabus if you are required to teach students the two's complement and other details then perhaps you will have to go through some additional material and additional examples but generally this kind of explanation is is adequate here is another question from GEC Triture how to return two values from a function at a time for example two roots of a quadratic equation an interesting question because the example that we took was that of a quadratic and quadratic will actually have two roots in fact a as simpler thing as a quadratic equation poses very curious problems it is not necessary that every quadratic should have two real roots it is not necessary that every quadratic must have two roots if the quadratic ax square plus bx plus c has b equal to 0 and c a is some value or say a is 1 as we saw we essentially reduces to square root which is a single value of course technically that single value can be positive or negative and therefore it has two real roots one on the positive side one on the negative side in case of a quadratic not only you can have two real roots anywhere on the x axis but you can also have complex conjugate rules the present Newton Raphson method sadly has no provision to handle that and such computations have to be handled differently coming back to the original question from our friend in GEC Triture can I make the function return two values the answer is yes and no no in the present form that we have returned the function and we have understood the function a function will only return one value that is the objective of a function even mathematically whenever we write some y is equal to f of x we actually have in mind a single value coming back it is not a set of values that the function returns yes because in real life there are situations that when we invoke a function we may want not just two but maybe a large number of values that is where later on after describing arrays and after looking at additional problems and their solutions we will comment on how a function can return multiple values the mechanism of returning multiple values is completely different and the return statement with which we associate a value to be returned can have only one value return and nothing more we are going over to NIT surat over to you thank you very much okay let me repeat the question for the benefit of AV users the question that is being raised by my friend from NIT surat is that how to call a function which is written separately by somebody else which is outside my program so we might use some examples of that at the moment let me tell you something whenever I use functions like scan f or print f these are proper functions by the way please notice that when these functions are called we are not defining them within our program they have been written by somebody else they exist somewhere else and indeed when we say include STD IO dot H we are not only including the header definitions of these but the entire function library is invoked by GCC system and those functions are linked to our program so a very simple and elegant way of describing to people is that the functions which we use as a part of the standard library functions say square root for example these are all functions which are written by somebody else they are part of the standard library in this case and they are invoked automatically whenever we call them in exactly the same fashion we shall see and I will include a example for your lab exercises somewhere where there are separately written functions which are compiled separately and which then can be invoked from within your program while you compile your program but while linking you link it with those functions also it is entirely possible thanks for this question I will include some examples in the exercises in the lab but the best way to tell our students is to say that look when I say print f or scan f I don't give the definition of that function although we now understand their functions so somebody else has written them they are part of the standard library and the C compiling and a runtime system automatically includes these compiled functions into our programs NIT Jalandhar is asking a question can the main function return a float value actually the main function can be can be written to return any value we can as I said most appropriate thing is to say void main because it is not expected to return any value the question actually is slightly ill founded because the purpose of returning a value from a function is that that function has done some meaningful calculations because somebody asked that function to do so and it has the responsibility of returning that value since the main program is in hold by the operating system and the control goes back to the operating system it is completely irrelevant as to what we return if you wish you can actually write float main it will compile but it will be a meaningless exercise because that value is not going anywhere the operating system is not going to do anything with it so we conclude by saying that while the main function can also return a value of any type since we do not know whom that value is returned to because we do not know the characteristics of operating system we do not know what will be done by that value and therefore it does not make sense to associate any value with the function main best bet is to call it void since we do not understand what void is now we can explain to our students that instead of saying in float or float if there is a function which does not have to return any value we can simply describe it as void something it tells the compiling system that this function will never return a value the question that now I would like to ask all of you is after all we discussed the notion of a function because we wanted to do some computation and return a value forget the operating system interaction with my program why would I ever think of writing a function within my program which does not return anything at all why would I think of a void function I would like all of you to think about it and come up with some examples I will include one example particularly a function which handles errors that means in a large program there could be errors that could be occurring and different modules will supply an error number like 1 2 3 4 5 instead of giving an error message to be printed or to be shown on the terminal by individual modules of the program it is not uncommon in a large software project to consolidate entire error reporting and invoke a single function to do that in that single function you will have variety of print f statements which will print some detailed message for error number 1 some detailed message for error number 2 etcetera etcetera. So, the only parameter given to that function is the error number which has been encountered somewhere else in the programs and what that function does is merely print an appropriate error message very clearly in such a case that function need not return anything back. So, this is one example of why a useful function may not return any value. However, the question about having to return more than one value is very pertinent and as I said we shall discuss this at a later stage. Thank you very much.