<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Shafi Sahal on Medium]]></title>
        <description><![CDATA[Stories by Shafi Sahal on Medium]]></description>
        <link>https://medium.com/@shafisahal?source=rss-f0afe23118d2------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*6AgKJxbQxnlGUbQ7DvCGRg.jpeg</url>
            <title>Stories by Shafi Sahal on Medium</title>
            <link>https://medium.com/@shafisahal?source=rss-f0afe23118d2------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Fri, 20 Nov 2026 21:59:01 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@shafisahal/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Simple Steps to Check The Legitimacy of Posts or News Before Sharing Them]]></title>
            <link>https://medium.datadriveninvestor.com/simple-steps-to-check-the-legitimacy-of-posts-or-news-before-sharing-them-a287e4f46b2e?source=rss-f0afe23118d2------2</link>
            <guid isPermaLink="false">https://medium.com/p/a287e4f46b2e</guid>
            <category><![CDATA[fact-checking]]></category>
            <category><![CDATA[fake-news]]></category>
            <category><![CDATA[politics]]></category>
            <category><![CDATA[social-media]]></category>
            <dc:creator><![CDATA[Shafi Sahal]]></dc:creator>
            <pubDate>Sun, 05 Nov 2023 07:12:03 GMT</pubDate>
            <atom:updated>2023-11-05T08:03:07.091Z</atom:updated>
            <content:encoded><![CDATA[<blockquote>“A Lie Can Travel Halfway Around the World While the Truth Is Putting On Its Shoes”</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/720/1*inK0dczq-TE9vNU1vm_CGw.jpeg" /><figcaption>source: <a href="https://roshankashmir.net/2022/02/13/class-10-result-authorities-issue-advisory-on-fake-messages/">https://roshankashmir.net/2022/02/13/class-10-result-authorities-issue-advisory-on-fake-messages</a></figcaption></figure><p>This age-old proverb implies that it’s in the nature of people to share rumors or falsehoods without any further verification. Thanks to social media, there now exists a fast and vast platform that can amplify this nature to share rumors manyfold. Inherently social media are meant to share information faster but like almost anything else it can be used negatively.</p><p>Basically, I find that there are two scenarios that make a person share posts without verification.</p><h4><strong>Posts that confirm a person’s biases</strong></h4><p>When there comes a post that confirms our biases we are eager to share it and want to believe it is true by default. We only want to verify it when someone points out it is not legit, and in some cases still people defend the post bluntly without any verification.</p><p>For example, some people are eager to share posts that confirm the positive aspects of the political party they are aligned with. In that case, they do not feel the need to verify the particular post. They had believed in it by default. At the same time, if the post is against the political party they are aligned with, it will be disbelieved by default and will be verified more crucially.</p><p>This is known as confirmation bias¹, a tendency to search for, interpret and recall information in a way that supports what we already believe.</p><h4>Sharing a post increases a person’s subjective knowledge</h4><p>When a person shares a post, he feels like he knows about the content the post is discussing even if he has not read it². So, in order to feel like they know about the content of a particular post or to make others feel they know about the content, some people share posts without further verification. We had witnessed this at the time of the Covid-19 spread. Baseless posts that promoted a prevention method for the disease such as drinking alcohol³ or the different conspiracies revolving around the origin of the virus⁴ were vastly shared on social media.</p><h3><strong>Simple steps to check the legitimacy of posts</strong></h3><h4><strong>Check the tone of the language</strong></h4><p>Posts whose content seems to be too good to be true are worthy of verification. Fake posts try to use emotions over intellect. For example, if some posts promise you to get rich quickly by doing what they suggest, verify before sharing. Various posts regarding pyramid schemes(MLM Scams), promise you to get wealthy by recruiting people, crypto-related investment scams and so on appear commonly on social media. Talk with them and understand how the business model works. If they give vague answers or mainly focus on the money aspect rather than the product or service, consider it as a red flag.</p><p>If the posts spread hatred against a community, individual or organization strictly verify the source and the context before sharing or even believing them. Fake news and posts have the potential to create tensions, chaos and riots. The 2023 Manipur violence in India has seen the potential of fake news to make people do terrible things⁵</p><p>Always read posts and analyze them intellectually before being emotional about them</p><h4><strong>Check the source</strong></h4><p>Whatever posts you intend to share, verify the source. If the post has the potential to create tensions, mislead people or scam people verify it for sure.</p><ul><li>Check whether the post has any links that back up its contents and check the legitimacy of the links. Check whether they are reputed or reasonably trustworthy sources.</li><li>If it’s news, check whether multiple reputed sources have reported the same news.</li><li>If it’s an image of a tweet or post of a famous person, go to his page and verify he has tweeted or posted the same.</li></ul><p>It’s very easy to fake a tweet. Not even need to do Photoshop.</p><p>Below is a simple way to fake a tweet from Nasa confirming the presence of aliens on Mars.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*EIrCVuB2z1ScxxDkVdAOSg.png" /><figcaption>image from author’s computer</figcaption></figure><ul><li>Right-click and select Inspect</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*dvhwVAIrOSC3gc4LI41EMA.png" /><figcaption>image from author’s computer</figcaption></figure><ul><li>Open the span element</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*RillKluWlN7EdbBDH28pVA.png" /><figcaption>image from author’s computer</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*WR9lDCeluPpgFdITxhJ2kw.png" /><figcaption>image from author’s computer</figcaption></figure><ul><li>Edit the content inside the span</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*1pTUlZIh2bYFyh2MqhR4DA.png" /><figcaption>image from author’s computer</figcaption></figure><ul><li>Share the screenshot</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*1bCivp-AKNE3JsoXZtzTyA.png" /><figcaption>image from author’s computer</figcaption></figure><p><strong>It’s that simple to create a fake tweet or post. So verify before sharing the screenshots of tweets.</strong></p><h4><strong>Google it</strong></h4><p>Just have a quick Google search regarding the content of the post and you will get lots of information about the content which may help you in verifying the legitimacy. Now I am not saying whatever there is on Google is legitimate, it’s just a tool that can help you with providing information. Use the information to verify.</p><h4><strong>Check the comments</strong></h4><p>If the post has a comment section, just check the comments. If people have already identified the post as fake, of course with legitimate sources and facts, you could easily identify it as fake without much effort.</p><h4><strong>Check if the person actually said what the post claimed</strong></h4><p>In many fake posts, quotes are used which the post claims to be said by some famous person.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*vUw-oLVeYHLblBnP3ixojQ.png" /><figcaption>image from author’s computer</figcaption></figure><p>This is a post claiming that Bill Gates said he would start network marketing if he would be given a chance to start all over. But if we search for the context of him saying this, whether he said it in an interview, or it is mentioned in an article he has written, or any legitimate sites, magazines or newspapers have credited this quote to him. In this case, we could not find any. All we get is some MLM scam sites using his image in an effort to market the company and some other sites that verify he has never said it. <strong>Such posts can easily make us think the scam is legit</strong></p><h4>Use Reverse Image Search to verify the source of Images</h4><p>Sometimes posts use old images that are out of context to increase the credibility of what they are sharing. Try verifying such images using reverse image search methods to reveal the source and context of the photo. We can see with an example how we may be able to search for the source and context of old images used to create fake posts.</p><h3>Subhash on Twitter: &quot;Now &quot;BIRIYANI JIHAD&quot; COIMBATORE POLICE CAUGHT MUSLIMS ! pic.twitter.com/k5mFrPnDxv / Twitter&quot;</h3><p>Now &quot;BIRIYANI JIHAD&quot; COIMBATORE POLICE CAUGHT MUSLIMS ! pic.twitter.com/k5mFrPnDxv</p><p>This is a post claiming that some Muslims in India are starting a so-called Biriyani jihad(biriyani is a dish in India), where the images hint at the usage of some drugs in the food served, and some other posts with the same images said that the drugs caused serious harm to people and the food with the drugs are served to Hindus and the plain food was served to Muslims. Many posts can use the same images to make more hateful content.</p><p>Steps to verify the source of the image:</p><ul><li>Download the image</li><li>Go to <a href="https://images.google.com/">https://images.google.com</a> and upload the image.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*eEeYJ0jfnLuq78ctCkKVtw.png" /><figcaption>image from author’s computer</figcaption></figure><p>As you can see there are many matches and because this was verified as fake by reputed fact-checkers like Boom, The Quint and by the police department, you can easily find the articles confirming this post is fake.</p><p>Still, we are not able to find the source of the images. This post is made of a collection of three images. Let’s crop each one of them and see if there are results. Chances are there since the images are together google may not be able to find a match but if we search one by one there may be matches.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*mM4AzqJz52yi9VlFL8cmkQ.png" /><figcaption>image from author’s computer</figcaption></figure><p>As you can see when we searched with the image of the man serving the food, we got one link having the description “7kg Mutton Dum Biriyani Method Explained”. Here is the link: <a href="https://searchblognow.wordpress.com/2021/07/23/7kg-mutton-dum-biryani-method-explained-distributed-to-needy-peoples-cooking-with-jabbar-bhai/">https://searchblognow.wordpress.com/2021/07/23/7kg-mutton-dum-biryani-method-explained-distributed-to-needy-peoples-cooking-with-jabbar-bhai/</a></p><p>When you open the link and scroll down you will see the particular image which on click leads to a YouTube video that explains how to make Biriyani. This image is the thumbnail of the video. So we got the source, it is an old unrelated image taken out of context for creating the fake post. Now we can search for the source of the image with the tablets.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*coTKXb2lHA6em4eg_qtKSA.png" /><figcaption>image from author’s computer</figcaption></figure><p>Here we were not able to see any posts with this exact image except some fact-checking sites that already verified this post is fake. In this case, we can do one more thing, we can crop the image we downloaded and try uploading it as a single image and check if it could lead us somewhere.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*lx2SSdC0XRcezpPLZycPYA.png" /><figcaption>image from author’s computer</figcaption></figure><p>Yes, now we could see a post by Dailymirror.uk telling of a drug case. Here is the link to the site:<a href="https://www.dailymirror.lk/Latest-News/Father-son-nabbed-with-illegal-drugs/108-166288">https://www.dailymirror.lk/Latest-News/Father-son-nabbed-with-illegal-drugs/108-166288</a>.</p><p>Unfortunately, the image with the police officers is giving a lot of matches because there are many images similar to them which makes the search for the source difficult but we could verify two of the images as unrelated. Even if one image is found unrelated to the post, we could highly suspect its legitimacy.</p><p>Now we have the source of the two images and confirmed they are unrelated to the post. This is how misleading fake images can be. <strong>They also have the potential to spiral communal hatred.</strong></p><p>Using the above-mentioned steps you could have a quick check on the legitimacy of posts and news. Following them does not guarantee that they will enable us to verify the legitimacy every time but still, these steps will help in many cases. There can be cases where reputed media, channels, or government can provide fake news which may need further detailed investigation to verify the legitimacy. But at least let’s have a brief and quick verification of the posts we share that may have sensitive content.</p><h3>References:</h3><ol><li>Don’t let confirmation bias narrow your perspective. <a href="https://newslit.org/tips-tools/dont-let-confirmation-bias-narrow-your-perspective/#:~:text=Confirmation%20bias%20is%20the%20tendency,calls%20our%20beliefs%20into%20question">https://newslit.org/tips-tools/dont-let-confirmation-bias-narrow-your-perspective/#:~:text=Confirmation%20bias%20is%20the%20tendency,calls%20our%20beliefs%20into%20question</a>.</li><li>Few People Read What They Share <a href="https://www.psychologytoday.com/us/blog/misinformation-desk/202212/study-few-people-read-what-they-share#:~:text=People%20Don&#39;t%20Always%20Read%20Before%20They%20Share&amp;text=Indeed%2C%20a%20majority%20of%20the,the%20person%20who%20posted%20them">https://www.psychologytoday.com/us/blog/misinformation-desk/202212/study-few-people-read-what-they-share#:~:text=People%20Don&#39;t%20Always%20Read%20Before%20They%20Share&amp;text=Indeed%2C%20a%20majority%20of%20the,the%20person%20who%20posted%20them</a>!</li><li>Drinking alcohol does not protect you against COVID-19 and can be dangerous <a href="https://www.who.int/emergencies/diseases/novel-coronavirus-2019/advice-for-public/myth-busters#alcohol">https://www.who.int/emergencies/diseases/novel-coronavirus-2019/advice-for-public/myth-busters#alcohol</a></li><li>Covid-19 5G theories are ‘most common’ misinformation <a href="https://www.bbc.com/news/technology-52370616">https://www.bbc.com/news/technology-52370616</a></li><li>2023 Manipur violence and fake news <a href="https://economictimes.indiatimes.com/news/india/how-fake-news-and-videos-inciting-violence-in-manipur/articleshow/102065845.cms?from=mdr">https://economictimes.indiatimes.com/news/india/how-fake-news-and-videos-inciting-violence-in-manipur/articleshow/102065845.cms?from=mdr</a></li></ol><p>Subscribe to DDIntel <a href="https://www.ddintel.com/">Here</a>.</p><p>Have a unique story to share? Submit to DDIntel <a href="https://datadriveninvestor.com/ddintelsubmission">here</a>.</p><p>Join our creator ecosystem <a href="https://join.datadriveninvestor.com/">here</a>.</p><p><a href="https://ddintel.datadriveninvestor.com/"><em>DDIntel</em> </a>captures the more notable pieces from our <a href="https://www.datadriveninvestor.com/"><em>main site</em></a> and our popular <a href="https://medium.datadriveninvestor.com/"><em>DDI Medium publication</em></a>. Check us out for more insightful work from our community.</p><p>DDI Official Telegram Channel: <a href="https://t.me/+tafUp6ecEys4YjQ1">https://t.me/+tafUp6ecEys4YjQ1</a></p><p>Follow us on <a href="https://www.linkedin.com/company/data-driven-investor"><em>LinkedIn</em></a>, <a href="https://twitter.com/@DDInvestorHQ"><em>Twitter</em></a>, <a href="https://www.youtube.com/c/datadriveninvestor"><em>YouTube</em></a>, and <a href="https://www.facebook.com/datadriveninvestor"><em>Facebook</em></a>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a287e4f46b2e" width="1" height="1" alt=""><hr><p><a href="https://medium.datadriveninvestor.com/simple-steps-to-check-the-legitimacy-of-posts-or-news-before-sharing-them-a287e4f46b2e">Simple Steps to Check The Legitimacy of Posts or News Before Sharing Them</a> was originally published in <a href="https://medium.datadriveninvestor.com/">DataDrivenInvestor</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Is there anything real out there and does it even matter?]]></title>
            <link>https://medium.datadriveninvestor.com/is-there-anything-real-out-there-and-does-it-even-matter-2f5cd67519b8?source=rss-f0afe23118d2------2</link>
            <guid isPermaLink="false">https://medium.com/p/2f5cd67519b8</guid>
            <category><![CDATA[philosophy]]></category>
            <category><![CDATA[reality]]></category>
            <category><![CDATA[life]]></category>
            <category><![CDATA[physics]]></category>
            <category><![CDATA[morality]]></category>
            <dc:creator><![CDATA[Shafi Sahal]]></dc:creator>
            <pubDate>Tue, 08 Nov 2022 12:59:45 GMT</pubDate>
            <atom:updated>2022-11-09T13:41:33.810Z</atom:updated>
            <content:encoded><![CDATA[<blockquote>Illusion is always based on reality, for its strength depends upon its fit with the desires, fears and experiences of countless humans — John P. Grier</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*spYq682z3FVoK6-q5tbm0g.jpeg" /></figure><p>Green trees, beautiful flowers, and the butterfly on the flower. Tall buildings, wide roads beneath them, and the vehicles moving through, altogether a beautiful scenery and we see them through our eyes, through the sense of vision. Birds screeching, beautiful melodies, soothing voices, we hear them through our ears, through the sense of hearing. Spices and sweetness, bitter and sour, through our tongue, through taste. Aromatic fragrances through smell. Hot, cold, pain, and touch through the skin. We sense reality with our senses of vision, hearing, taste, smell, and feel but is the reality that we know exists as it is?</p><p>What we get through our senses is information provided by the environment around us and we create a model by combining this information and that model serves as the reality for us. The light provides the information and our brain converts it into vision. The vibrations provide information which brain converts to sound. The microscopic particles that hit the neurons in the nose are converted to smell. Pressure and temperature that hits the neurons on the skin are converted to touch, pain, hot and cold.</p><blockquote>What’s interesting is that if we are modeling our reality based on the information provided by the environment, then the same reality can be modeled even if the information is faked.</blockquote><p>This is what happens in virtual reality. Even though know that VR is not REAL reality, at the time we fall from a height or get attacked in the VR, our bodies take those as real information for some amount of time. The only reason we know it is a VR is because we have the memory of our outside reality and it is we who got into VR. Suppose a man gets completely into VR, and he is not able to get out of it for a determined period or without external help and this man forgets the outside reality and memory of him getting into VR, it would be very hard or literally impossible for him to know whether this is a VIRTUAL reality or REAL reality.</p><p>If that is the case, we have no way to know whether the reality we live in is real. We can be living in a simulated reality and we may be modeling our reality based on the information provided by the simulator. From the subatomic particles to the distant galaxies nothing can be examined and assured whether they are real or simulated.</p><p>If it is so and any object in the universe cannot be given a guarantee to be real, then to judge someone based on materialistic things: wealthy or poor, living in a small apartment or mansion, comparison based on income, number of things owned, everything seems to make no sense. All of these things are material and hence do not guarantee to be real. Basically, everything might be a delusion. This world may be a delusion.</p><p>That may be a good concept, at least partially, because if there is no point in being materialistic, many wars might have not occurred as there is no point in fighting over land and money. Flaunting the luxurious life and items some people have may be pointless if all of that has no guarantee to be real. So maybe people start to live with more insight and maybe they judge others based on any other aspects which could be better than something which has a possibility to be a delusion. But if that is so, then there arises another problem.</p><blockquote>If anything cannot be guaranteed to be real, so is life</blockquote><p>If every particle in this world has a possibility to be not real, then the life we live here in the world, with our materialistic bodies cannot be guaranteed to be real and hence life need not be considered something of value. If someone takes this perspective, then it may make sense to start a war for land and money because for him all of these are not absolutely real and out of all the not-real things, he chose wealth to be something that has more value in his life than some human lives which will be lost in the process of acquiring it. And most importantly, he cannot be considered wrong or unjust with this perspective. Finally, “In the end, it doesn’t even matter”.</p><blockquote>So, there should be something that is real to solve this dilemma or is their not?</blockquote><p>And yes, there is something that is guaranteed to be real and this thing doesn’t need high-end technologies, research facilities, extreme intelligence, or mind-boggling theories. We experience this REAL thing almost every moment in our life. That is “<strong>EXPERIENCE</strong>”.</p><p>The vision we experience is real irrespective of the reality of the information provided. Be it from a real environment or from a simulated one, if we see, if we experience vision, that “experience of the vision” is real. So is it with all the other senses: the experience of hearing, smelling, and feeling. The pain you experience when a bee stings you is absolutely real irrespective of whether the bee is real or simulated.</p><p>Moreover, experiences are not limited by them. There are a whole lot more experiences that can be experienced. Fear, anger, jealousy, compassion, kindness, bravery, happiness, sadness, calmness, disturbance, love, hatred, hunger, greed, excitement, and the list goes on. The fear a deer experiences while being chased by a lion and the hunger experienced by the lion, for to satisfy it the lion is chasing the deer, are absolutely real. Hunger formed in starving people is an absolutely real thing even if the whole world is a delusion.</p><p>What experiences we value over others, basically determines us. It is whether we value compassion over harshness, kindness over cruelty, calmness over anger, or the other way around that makes us noble or degraded. It is whether one values greed over humbleness or humbleness over greed that determines whether it is right for him to fight wars to acquire materials at the cost of lives, or whether it is better to live in harmony and peace.</p><blockquote>If experience is the only thing that can be guaranteed to be real irrespective of the things that help the experience to form is real or not, is buying expensive things bad or is wealth bad, or is luxury?</blockquote><p>It again depends on what experience we value. Are we buying a top-brand smartphone for increasing productivity so that we can complete our tasks faster and better so that we can experience a sense of achievement, or for the experience of using it, or is it for the love of that marvelous device itself, or is it because of the status gain, or is it because we can flaunt it?. The same is the case when someone buys a car. Is he buying the car for the experience of driving it, or for increasing productivity? and so on. The answers to these questions determine whether buying it is good or bad. Answers to such questions determine whether some of our decisions are good or bad.</p><p>In a nutshell, even if we live in a real reality or a simulated one, we can be sure that the experiences we experience are absolutely real and so it is better for us to focus on our experiences than materialistic things. It is better to judge a person based on his experiences of life, and our experiences with him in life rather than judging based on the materialistic things related to him. And finally, “<strong>In the end, still something matters</strong>”</p><p>Subscribe to DDIntel <a href="https://ddintel.datadriveninvestor.com/">Here</a>.</p><p>Visit our website here: <a href="https://www.datadriveninvestor.com/">https://www.datadriveninvestor.com</a></p><p>Join our network here: <a href="https://datadriveninvestor.com/collaborate">https://datadriveninvestor.com/collaborate</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=2f5cd67519b8" width="1" height="1" alt=""><hr><p><a href="https://medium.datadriveninvestor.com/is-there-anything-real-out-there-and-does-it-even-matter-2f5cd67519b8">Is there anything real out there and does it even matter?</a> was originally published in <a href="https://medium.datadriveninvestor.com/">DataDrivenInvestor</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Why Does Every Voice Matter? The Importance of Hearing Different Perspectives]]></title>
            <link>https://medium.com/curious/why-does-every-voice-matter-the-importance-of-hearing-different-perspectives-eeba740955ab?source=rss-f0afe23118d2------2</link>
            <guid isPermaLink="false">https://medium.com/p/eeba740955ab</guid>
            <category><![CDATA[philosophy]]></category>
            <category><![CDATA[self-development]]></category>
            <category><![CDATA[perspective]]></category>
            <category><![CDATA[self-improvement]]></category>
            <category><![CDATA[politics]]></category>
            <dc:creator><![CDATA[Shafi Sahal]]></dc:creator>
            <pubDate>Tue, 19 Oct 2021 22:47:11 GMT</pubDate>
            <atom:updated>2021-10-19T22:47:11.918Z</atom:updated>
            <content:encoded><![CDATA[<h4>May all of us be able to form better conclusions and make better decisions.</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*whHK7suWlw-jWyuMoNKHwA.gif" /><figcaption>source:<a href="https://in.pinterest.com/pin/558868634981942954/">https://in.pinterest.com/pin/558868634981942954/</a></figcaption></figure><blockquote>“Opinion is really the lowest form of human knowledge. It requires no accountability, no understanding. The highest form of knowledge… is empathy, for it requires us to suspend our egos and live in another’s world. It requires profound purpose larger than the self kind of understanding.” — — Bill Bullard</blockquote><p>“I know I am right” and “You are just wrong”. All of us might have spoken these lines at least once, most probably many more times in our life, maybe between a debate or a discussion, or in arguments or fights. Now, the statements themselves are not the problem and maybe sometimes someone is exactly right and the other one is exactly wrong but it’s how much time we put into hearing the other person’s perspective and how much time we put in to see and think through the other person’s point of view before we make a conclusion and even if made a conclusion, was the motivation to say someone is wrong is just an emotional attack onto that person or is it that our ego is not allowing us to accept the rightness in the other person or is it the concern to make that person understand?</p><p>Each and every one of us want to be right or at least we want others to perceive our point as right, though the reasons for such a tendency may vary. Unfortunately, we are humans and hence not supernatural. Everyone cannot be right. This implies that every one of us has more than enough chance to be wrong in many areas, in many points we make, in many arguments we argue, in many answers we answer and that’s fine and more importantly that is normal. That just shows you are a human. Admitting we are wrong does not lower our dignity. It shows we are responsible, humble, and moreover growing intellectually. Only when we understand our mistakes we are able to improve ourselves.</p><p>Now does that mean we should admit that we are wrong even if we are right? Absolutely not, and I have done that mistake to not break some relations. So, now I know why it was not a good idea. It is never about admitting we are wrong even if we are right. It’s about whether we have considered the perspective of the other person and when we consider others&#39; perspectives, sometimes we may get surprised and ask ourselves “Isn’t what he/she telling is right? Why have I never thought about this?”</p><h3>Perspective-taking</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*s5pfvaveZsEZMIqSJ7EtkA.jpeg" /><figcaption>source:<a href="https://www.hdnicewallpapers.com/Wallpaper-Download/Deer/Deer-Crossing-Road-in-Yosemite-National-Park">https://www.hdnicewallpapers.com/Wallpaper-Download/Deer/Deer-Crossing-Road-in-Yosemite-National-Park</a></figcaption></figure><p>Now, a pretty simple question: What is that image about? It’s a deer crossing the road. Hmm, exactly that’s what it is about and we can see with our own eyes that there is a deer crossing the road.</p><blockquote>Now, change the perspective. Think from the perspective of the deer. When we do that, we find that to be precise, it’s not the deer crossing the road but a road crossing the forest.</blockquote><p>The forest is the habitat of the deer and it is we who have built roads through its habitat. To the deer, it’s just roaming around its homeland. Will we ever be able to see that dimension without considering the perspective of the deer?</p><p><a href="https://pubmed.ncbi.nlm.nih.gov/28215285/">Perspective-taking¹</a> or “theory of mind,” involves reasoning about the mental states of others (e.g., their intentions, desires, knowledge, beliefs). E<a href="https://www.britannica.com/science/egocentrism">gocentrism²</a> is the opposite of perspective-taking which is the inability to consider others’ perspectives.</p><p>As far as we are humans and not supernatural, perspective-taking is the only way by which we can form better decisions, find better solutions or answers, ask better questions, get closer to truth or understand reality. As all of us have heard perception is reality and not using perspective-taking may lead one to not live in the reality for their whole life.</p><h3>Why should we care about all of these?</h3><p>This is a question that comes to my mind very often: “Shafi, why do you care about all of these? Think about something that is useful for you. Be productive my boy”. That question was not pointless. It was holding some truth in it. After all, I have heard many people tell to not care about these things that are not useful to oneself. It’s the era of “Be yourself and don’t care about what others think”. It does not matter what is the view of others.</p><p>While it is bad to always think about what others are thinking about you and it is bad to judge others based on irrelevant parameters, it is equally bad to not take into consideration the voice of others. Listen to everyone but not believe everyone nor make conclusions merely from others views.</p><p>What we gain from considering others&#39; perspectives is data. Gain the data and get more insights into the data by using tools such as the internet, books, articles, or speeches and then let your mind analyze it with your intelligence, knowledge, experiences. and form conclusions based on that. This simple yet powerful strategy helped me to get more accurate insights on different subjects.</p><p>What if one just did not care about others’ perspectives and only thinks about matters or views that are useful to him or in favor of him? He is just not going to identify any of his mistakes and live his whole life believing that the mistakes he made were actually the mistake of others. He just starts to blame everyone else for his mistakes too. In his perspective, he will be the one who is right and he sees no point in considering others’ perspectives.</p><h3>Role of technology in perspective-taking</h3><p>Technology, especially information technology is wonderful, marvelous, fantastic, and powerful. Like any other powerful tool, technology too can be used for good and for bad on a large scale.</p><p>The internet can give us a lot of information regarding almost all of the topics we could ever imagine. This is helpful for perspective-taking because the internet is a place where we can see lots of different perspectives and therefore we can make better conclusions as we have more data.</p><p>Personally, the internet has helped me a lot in making conclusions on different matters. For example, when I code and when a doubt arises about which method is better to accomplish the particular task, I search for the pros and cons of each method. These helped me most of the time to make better decisions.</p><p>The problem is when we are not aware of polarization, especially in social media the algorithms which are intended to show what is interesting to us do their work with a very good score.</p><blockquote>Now that is good and it only becomes a problem when we blindly believe that the only perspectives existing out there are the ones that the algorithm is showing. That leads us to egocentric behavior by taking away our ability to see others’ perspectives.</blockquote><h3>The take-away</h3><p>The main point I wanted to convey through all of these was that we are gifted with the power of reason and use that to make better decisions rather than relying purely on emotions or our own ego and neglecting whatever is existing outside of it. We are living in the best times for implementing such a strategy into our life. These technologies, power, and the ability to have information with minimal cost and high speed just came recently and are actually a blessing until we chose ourselves to use them just for our own little egoistic satisfactions.</p><p>Never believe someone blindly just because they are an expert in a particular field and never reject someone just because they are not an expert in that field. Always here everyone, use your reason and form conclusions unbiased.</p><p>Now does it in any way mean that by using this strategy we will be right all the time? Never, there is every possible chance for us being wrong at any point in time but perspective-taking can increase the chances of us reaching the right conclusions much higher and reducing the divide and conflicts between us.</p><p>May all of us be able to form better conclusions and make better decisions.</p><p>Here is a brilliant documentary-style video by MagnatesMedia which speaks about this topic in more detail in case if you want to get more insight into the topic.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2FHErV0qAzbZE%3Ffeature%3Doembed&amp;display_name=YouTube&amp;url=https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DHErV0qAzbZE&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2FHErV0qAzbZE%2Fhqdefault.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=youtube" width="854" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/a24c56768fc9e7bfd2c1d22a22dca5fb/href">https://medium.com/media/a24c56768fc9e7bfd2c1d22a22dca5fb/href</a></iframe><h3>References</h3><ol><li>Perspectives on Perspective Taking: How Children Think About the Minds of Others by S A J Birch, V Li, T Haddock, S E Ghrear, P Brosseau-Liard, A Baimel, M Whyte. Retrieved from: <a href="https://pubmed.ncbi.nlm.nih.gov/28215285/">https://pubmed.ncbi.nlm.nih.gov/28215285/</a></li><li>Egocentrism, Britannica article by Emily Pronin: <a href="https://www.britannica.com/science/egocentrism">https://www.britannica.com/science/egocentrism</a></li></ol><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=eeba740955ab" width="1" height="1" alt=""><hr><p><a href="https://medium.com/curious/why-does-every-voice-matter-the-importance-of-hearing-different-perspectives-eeba740955ab">Why Does Every Voice Matter? The Importance of Hearing Different Perspectives</a> was originally published in <a href="https://medium.com/curious">Curious</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to expose your PC to the internet without a public IP address?]]></title>
            <link>https://medium.com/geekculture/how-to-expose-your-pc-to-the-internet-without-a-public-ip-address-c7a2c808ab6b?source=rss-f0afe23118d2------2</link>
            <guid isPermaLink="false">https://medium.com/p/c7a2c808ab6b</guid>
            <category><![CDATA[networking]]></category>
            <category><![CDATA[web-app-development]]></category>
            <category><![CDATA[internet]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[web-development]]></category>
            <dc:creator><![CDATA[Shafi Sahal]]></dc:creator>
            <pubDate>Wed, 06 Oct 2021 14:02:47 GMT</pubDate>
            <atom:updated>2021-10-07T01:58:41.443Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*WG0ZwWlgXnGqvDH074vQzQ.jpeg" /></figure><p>Internet is fascinating: keeps everyone connected, made work from home a reality, and made the availability of information cheap and fast, yet the basic concepts of the internet are very simple. It’s just some shared files. Every website or web app you visit is just some files stored somewhere in another computer in the network. When someone enters the URL, a request is sent to the particular computer and the computer sends back the needed files to the one who made the request and it is viewed in the browser. Even if the basic concept is that simple, the internet just impacted the world on a very very large scale. It was really a revolution.</p><p>While it is able to request a file from another computer in the network, can we share our files with another computer? Internet is just a distributed network, so we might also be able to share files with another computer. Suppose you developed a cool web app and you want to showcase this to your friends or maybe the outside world. It could be done with the help of hosting providers where you just upload the files of your web app and it is run on a server provided by the provider.</p><p>Hosting on other platforms is great if your app is ready to be in production since it is more secure and the machines on which you host your app will have much higher performance and also the internet connection speed will be very fast.</p><p>But there are times when you just want to simply showcase your app to someone and not make it available for everyone or you may want to get feedback on your app simultaneously while developing. Hosting on a platform and learning how to host it on a hosting platform may be too much at this stage. Moreover, there are no completely free hosting solutions for dynamic web apps. Either there will be a limit in the amount of usage or you have to pay a fee.</p><p>There is a perfect solution for this and it is connecting your PC directly to the internet so that you can make the server on your machine listen to requests from the internet and do not need to host. Anyone who is able to reach the server in your machine can send requests to it or communicate with it. So, how do we do it? For that, let’s get into some basics of networking.</p><h3>IP Address</h3><p>An IP address is analogous to a physical address. Suppose if you want to send a courier to your friend, you provide the address of his home. Same as that IP address helps to identify machines in the network. When you type a URL in the browser, the URL is translated to the corresponding IP address with the help of <a href="https://www.cloudflare.com/en-in/learning/dns/what-is-dns/">DNS (Domain Name System)</a> and the request is sent to the particular IP address. The world is currently using the version 4 IP address known as the IPV4 address</p><p>IPV4 address is the 32-bit numerical address. There can be 4 billion possible IPV4 addresses. So, if we assign an IPV4 address to each machine, the machine can be uniquely identified from the whole network and can be communicated with. If that was the case yet, everyone could expose their PC very easily to the internet but that’s not the case now.</p><p>Even if IPV4 addresses can have 4 billion values, it has exhausted as the internet had grown rapidly. So, as of now only ISP’s and others like data centers or hosting providers have unique IPV4 addresses. It’s a little bit difficult to have a unique IP for ourselves. These unique addresses are known as public IP.</p><p>Private IP addresses are the ones that your router uses to identify the machines in a local network. So an ISP may assign a public IP address to your router and then the router will have an IP address pool. Each machine connected to the router will be given an IP address from the pool. These IP addresses assigned by the router will be private and are known as private IP addresses. The router itself will also be having a private IP address which is known as the default gateway. A machine in the local network sends the request to this default gateway IP.</p><h3>NAT(Network Address Translation)</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/797/1*k3ruG6SjvJOKBTkiEEzIYg.jpeg" /><figcaption>Source: <a href="https://www.comparitech.com/blog/vpn-privacy/nat-firewall/">https://www.comparitech.com/blog/vpn-privacy/nat-firewall/</a></figcaption></figure><p>NAT maps the public IP to the corresponding private IP, that is when a machine from the local network sends a request to a server through the internet, it first sends the request to the private IP of the router, then NAT maps the private IP to the public IP of the router. When the server sends a response back to the machine, it sends the request to the public IP of the router and NAT maps the public IP of the router to the private IP of the sender.</p><p>So, there is no need for a public IP for every device if the device shares the same local network. This also increases security as no one can connect directly to a device behind NAT. <a href="https://www.lifewire.com/how-to-port-forward-4163829">If your router has a public IP, you can expose your PC to the internet by port-forwarding which is very simple</a>.</p><p>The problem is that sometimes even the router will not have a public IP as the router is just behind another NAT which means that the router itself is a device in a larger local network. Instead of assigning public IP for every router, the ISP may use a NAT and assign a private IP to the router. So there will be a local network of routers just under the ISP and under each router, there will be a local network of computers or mobile phones. This is intended for increased security and also to decrease the usage of the public IP.</p><h3>Exposing PC to the internet without a public IP</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*amWPjjI_oDjMOGMTd-PKkQ.png" /></figure><p>This is my application running on a Nodejs server at port 3000. This application is on my PC.</p><p>To expose a PC to the internet without a public IP:</p><ul><li>Download and install OpenVPN. In my ubuntu 20.04, it was preinstalled.</li><li>Goto <a href="https://portmap.io/">https://portmap.io/</a></li><li>Create an account(it’s free)</li><li>Click on the configurations tab</li><li>Add a new configuration, select the protocol, give a configuration name and then save the configuration and download the configuration file.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*jMrFqDScNa17QacKcOOpBw.png" /></figure><ul><li>Goto mapping rules tab and create a new mapping rule.</li><li>Set the protocol as ‘http’</li><li>On the ‘Port on your PC’ field provide the port on which the server is running on your machine. In this case, 3000 as my server is running on 3000.</li><li>Save the rule.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Nq-LGBzMx89PEoDvC9oYWw.png" /></figure><ul><li>Now open a terminal and navigate to the location where the configuration file is downloaded and enter the command</li></ul><pre>sudo openvpn --config &lt;Your downloaded config file name&gt;</pre><p>If the ‘initialization sequence completed’ message appears you are set to go.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Y0jBhG6gIQrYGQxFwdj_Qg.png" /></figure><p><a href="https://www.cloudflare.com/en-in/learning/network-layer/what-is-tunneling/">Now, the OpenVPN sets up a tunnel from your machine to the portmap.io website.</a> Send the URL which was generated by the portmap.io after saving the mapping rule to your friends and when they click on it a request is sent to the portmap.io to the specified port in the URL and the portmap.io redirects that URL to the specified port in your PC.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*E1KlVvLGc3wsLrqWktHMUw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*v-WjEmeaQnf9RxTAtjtqsw.png" /></figure><p>Now you can connect communicate with your server from anywhere in the world!!!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c7a2c808ab6b" width="1" height="1" alt=""><hr><p><a href="https://medium.com/geekculture/how-to-expose-your-pc-to-the-internet-without-a-public-ip-address-c7a2c808ab6b">How to expose your PC to the internet without a public IP address?</a> was originally published in <a href="https://medium.com/geekculture">Geek Culture</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Implementing a search bar for filtering select-dropdowns in Angular]]></title>
            <link>https://medium.com/geekculture/implementing-a-search-bar-for-filtering-select-dropdowns-in-angular-63b1f2033737?source=rss-f0afe23118d2------2</link>
            <guid isPermaLink="false">https://medium.com/p/63b1f2033737</guid>
            <category><![CDATA[angular-material]]></category>
            <category><![CDATA[angular]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[angular2]]></category>
            <category><![CDATA[open-source]]></category>
            <dc:creator><![CDATA[Shafi Sahal]]></dc:creator>
            <pubDate>Tue, 21 Sep 2021 22:03:16 GMT</pubDate>
            <atom:updated>2021-09-22T02:49:20.883Z</atom:updated>
            <content:encoded><![CDATA[<h3>Implementing a search bar for filtering the options in the select-dropdowns in Angular</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*FNnzkTo3JMa9drO935AF4g.png" /></figure><p>During one of my projects, it was needed to implement a select-dropdown for showing the countries with their respective dial codes and the user should be able to search through them. This was to make the mobile number in the right format.</p><p>Unfortunately, I came to know that Angular Materials does not provide that functionality. So, I thought if I could have a workaround using the matAutoComplete. I have seen some Github comments about the workaround but they were not powerful enough and were a bit complicated.</p><p>The issue has been addressed to the angular material team by many through a Github issue a long time ago. The team says they are looking for a solution and they will implement it and yeah they may have got more important problems to solve. You can check about the issue here: <a href="https://github.com/angular/material2/issues/5697">https://github.com/angular/material2/issues/5697</a></p><p>So as usual, I tried searching for libraries to do the work till the angular team implement the feature and I found a couple of them, but they were either too simple to be any powerful or were too complicated and verbose to be convenient.</p><p>That’s when I thought about trying to develop a library to solve this problem. I wanted to make it simple to use and yet it should be powerful and that’s what MatSelectSearch has become. So finally, there is a solution to this problem.</p><h3>MatSelectSearch</h3><p>npm link: <a href="https://www.npmjs.com/package/mat-select-search">https://www.npmjs.com/package/mat-select-search</a></p><p>MatSelectSearch is an Angular component providing functionality to search/filter MatSelect options of the Angular Material library which is simple to use and more powerful than any other library that aims to solve this problem currently. The search functionality is optimized too, that is MatSelectSearch is able to search through long lists faster than the current libraries for the same.</p><h3>How to use it?</h3><p>Install mat-select-search in your project</p><pre>npm install mat-select-search</pre><p>Import the mat-select-search into the app module. In case lazy loading is being used, import it into the particular module where you need the library.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/7e1117fde7cf9a470fb146f2a2ce0ab6/href">https://medium.com/media/7e1117fde7cf9a470fb146f2a2ce0ab6/href</a></iframe><p>Place the lib-mat-select-search component inside a mat-option of the mat-select.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/27265e1694c46e8013e4ed91be89a8e0/href">https://medium.com/media/27265e1694c46e8013e4ed91be89a8e0/href</a></iframe><p>There are two inputs to be passed to enable the search:</p><ul><li>[list]</li><li>[searchProperties]</li></ul><p>There is one event fired after filtering the mat-options</p><ul><li>(filtered)</li></ul><h3>[list]</h3><p>Pass the array to be filtered to the lib-mat-select-search through the [list] input.</p><pre>[list]=&quot;countries&quot;</pre><h3>[searchProperties]</h3><p>Pass the properties which are to be searched to the [searchProperties] input. Now, here mat-select-search is providing a unique functionality that the other current libraries do not provide.</p><p>mat-select-search supports multi-property search. Consider a scenario where you have a list of countries as such:</p><pre>[<br>  {<br>    name: &quot;India&quot;,<br>    dialCode: &quot;+91&quot;,<br>    code: &quot;IN&quot;<br>  },<br>  {<br>    name: &quot;Indonesia&quot;,<br>    dialCode: &quot;+62&quot;,<br>    code: &quot;ID&quot;<br>  },<br>..............and goes on</pre><p>Now, suppose there is a use case where the search should happen not only by name but also with dialCode and code. So, even if the user types the dialCode of the country or the code of the country, the search should be happening. To enable this property in mat-select-search there is no extra overhead.</p><p>[searchProperties] receives an array of strings. The strings are the properties by which the search should happen. So, in case if the search should happen only by the name provide:</p><pre>[searchProperties]=&quot;[&#39;name&#39;]&quot;</pre><p>If the search should happen by name, dialCode and code, just provide:</p><pre>[searchProperties]=&quot;[&#39;name&#39;, &#39;dialCode&#39;, &#39;code&#39;]&quot;</pre><p>It’s as simple as that.</p><p>Now, the order by which the properties are provided matters a bit. If the properties are provided in the above manner, the search term ‘India+91’ will still give the correct result but not ‘+91India’. Consider the order if you got any particular use case where this matters. In most cases, it does not matter. So the order of the properties does not matter much.</p><h3>(filtered)</h3><p>(filtered) is an event that is fired after filtering the mat-options. Store this filtered array into another variable.</p><pre>//Storing the filtered array in filteredCountries<br>(filtered)=&quot;filteredCountries = $event&quot;</pre><p>And that’s it. Now mat-select-search is ready and you can implement the search!!!</p><p>The [list] and [searchProperties] are the required inputs for the search to work. There are optional inputs too that provide some customization.</p><h3>[clearSearchInput]</h3><p>[clearSearchInput] is set to false by default. When set to true, the search bar will be cleared after the mat-select is closed so that when the mat-select is reopened the search bar will be empty.</p><h3>[fixOnTop]</h3><p>[fixOnTop] is set to false by default. When set to true, the search bar position is fixed on the top and it does not scroll with the mat-options, so it is visible even while scrolling.</p><p>So, why not set it to true by default?. It’s because the search bar never loses focus. So even if it is scrolled upwards and is not visible, just press any key and the search bar appears and the search happens. So, there is not necessarily a need to fix it on top. Especially for mobile devices, it is better to make it scroll, so the unwanted space is saved and a mat-option will be displayed in its place.</p><p>Also, if a user prefers scrolling rather than typing, the search bar is purely a waste of space. So, [fixOnTop] is set to false by default and if someone wants it to stay at the top, it’s still possible, just set [fixOnTop] to true.</p><h3>[hasSelectAll]</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/672/1*uONNb0bKs3GtA1z-a59MIQ.png" /></figure><p>[hasSelectAll] is set to false by default. When set to true, it provides functionality to have an option to select all the mat-options in the multiple select.</p><p>Also, provide a mat-option for ‘Select All’ and place it below the mat-option for lib-mat-select-search.</p><pre>&lt;mat-option&gt;Select All&lt;/mat-option&gt;</pre><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/4a0c2783c61df8cd949976eb27069960/href">https://medium.com/media/4a0c2783c61df8cd949976eb27069960/href</a></iframe><h3>How to make MatSelectSearch work with formArray?</h3><p>While working with formArray, it is not enough to just store a single filtered array. There should be a filtered array for each form.</p><p>Imagine a scenario where there are multiple forms and each one has a mat-select to select the country. With the same logic as above, the search will work perfectly for the mat-select whichever the user interacts with initially but while interacting with another mat-select, the value of the first mat-select will be gone. This is because the variable ‘filteredCountries’ is shared by all the mat-select.</p><p>So, to solve all these problems, make ‘filteredCountries’ a 2-d array and store the filtered array in the respective index of the ‘filteredCountries’.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/5f6ba336d291c571e68534d0e483abc4/href">https://medium.com/media/5f6ba336d291c571e68534d0e483abc4/href</a></iframe><p>If you liked this component or if it has been helpful to you in solving your problems, please star the repo: <a href="https://github.com/shafi-sahal/MatSelectSearch">https://github.com/shafi-sahal/MatSelectSearch</a>.</p><p>Contributions, feedback, and suggestions are always welcome.</p><p>You can download the library from here: <a href="https://www.npmjs.com/package/mat-select-search">https://www.npmjs.com/package/mat-select-search</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=63b1f2033737" width="1" height="1" alt=""><hr><p><a href="https://medium.com/geekculture/implementing-a-search-bar-for-filtering-select-dropdowns-in-angular-63b1f2033737">Implementing a search bar for filtering select-dropdowns in Angular</a> was originally published in <a href="https://medium.com/geekculture">Geek Culture</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Learn the Core Coding Concepts intuitively]]></title>
            <link>https://shafisahal.medium.com/learn-the-core-coding-concepts-947859146239?source=rss-f0afe23118d2------2</link>
            <guid isPermaLink="false">https://medium.com/p/947859146239</guid>
            <category><![CDATA[programming-languages]]></category>
            <category><![CDATA[tutorial]]></category>
            <category><![CDATA[c]]></category>
            <category><![CDATA[coding]]></category>
            <category><![CDATA[programming]]></category>
            <dc:creator><![CDATA[Shafi Sahal]]></dc:creator>
            <pubDate>Sun, 22 Aug 2021 16:25:24 GMT</pubDate>
            <atom:updated>2021-08-22T16:27:34.516Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1000/1*Lt8A9JzdyDAjVimCfD6Exw.jpeg" /></figure><h3>Contents</h3><ol><li><a href="https://medium.datadriveninvestor.com/code-factory-377323ed504">Introduction</a></li><li><a href="https://medium.datadriveninvestor.com/codefactory-hello-world-f5ae4ed545d2">Hello World</a></li><li><a href="https://medium.datadriveninvestor.com/code-factory-variables-and-data-types-aa20cfccfe80">Variables and Data Types</a></li><li><a href="https://medium.datadriveninvestor.com/code-factory-algorithm-16502f8709b6">Algorithm</a></li><li><a href="https://medium.datadriveninvestor.com/code-factory-arithmetic-operators-697082818925">Arithmetic Operators</a></li><li><a href="https://medium.com/geekculture/code-factory-relational-operators-3a0f2f06e638">Relational Operators</a></li><li><a href="https://medium.com/geekculture/the-logic-in-logical-operators-1cb16f4f0af3">The Logic in Logical Operators</a></li><li><a href="https://medium.com/geekculture/how-to-interact-with-users-in-programming-d9eaebb565c1">How to Interact with Users in Programming?</a></li><li><a href="https://medium.com/geekculture/decision-making-in-programming-743e86895ce4">Decision Making in Programming</a></li><li><a href="https://medium.com/geekculture/decision-making-with-switch-statement-9dcfc2a71dfb">Decision Making with Switch Statement</a></li><li><a href="https://medium.com/geekculture/repeating-logic-in-programming-4035ebf392d5">Repeating Logic in Programming</a></li><li><a href="https://medium.com/geekculture/arrays-store-multiple-items-using-the-same-variable-7e2af6e2bdf">Arrays — store multiple items using the same variable</a></li><li><a href="https://medium.com/geekculture/string-an-array-of-characters-with-0-a133fd56e9d9">String — An array of characters with ‘\0’</a></li><li><a href="https://medium.com/geekculture/functions-reusable-logic-b1fad28e72cb">Functions — Reusable Logic</a></li><li><a href="https://medium.com/geekculture/array-of-strings-95621fdf85a0">Array of Strings</a></li></ol><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=947859146239" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Array of Strings]]></title>
            <link>https://medium.com/geekculture/array-of-strings-95621fdf85a0?source=rss-f0afe23118d2------2</link>
            <guid isPermaLink="false">https://medium.com/p/95621fdf85a0</guid>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[programming-languages]]></category>
            <category><![CDATA[arrays]]></category>
            <category><![CDATA[string]]></category>
            <category><![CDATA[c-language]]></category>
            <dc:creator><![CDATA[Shafi Sahal]]></dc:creator>
            <pubDate>Wed, 11 Aug 2021 07:02:30 GMT</pubDate>
            <atom:updated>2021-08-15T13:36:55.277Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/488/1*bgzSD35orZtO9bTdudUnzA.png" /></figure><p>This article is about how to use an array of strings. <a href="https://medium.com/geekculture/arrays-store-multiple-items-using-the-same-variable-7e2af6e2bdf">Check this one if you want to know what an array is.</a> Using string arrays is not a big deal and is the same as using other array data types in new languages. Anyway, it’s different with C, and understanding how a string array is implemented in C helps to understand the behind-the-scenes of the string array implementation in those new languages.<a href="https://medium.com/geekculture/string-an-array-of-characters-with-0-a133fd56e9d9"> To know about strings check this.</a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/488/1*bgzSD35orZtO9bTdudUnzA.png" /></figure><p>As you can see from the image, the array of strings is a <a href="https://medium.com/geekculture/arrays-store-multiple-items-using-the-same-variable-7e2af6e2bdf">2-dimensional array</a>. <a href="https://medium.com/geekculture/arrays-store-multiple-items-using-the-same-variable-7e2af6e2bdf">The string itself is a 1-dimensional array.</a> So, the array of strings will be a 2-dimensional array. In the image, the names of the cities are stored as a 2-d array. To access a city just use “cities[index]”;</p><pre>cities[0] // Gives Pune<br>cities[1] // Gives Mumbai</pre><h3>Declaring a string array</h3><pre>char cities[4][6] = {<br>                      &quot;Pune&quot;,<br>                      &quot;Mumbai&quot;,<br>                      &quot;Delhi&quot;,<br>                      &quot;Nagpur&quot;<br>                     };</pre><p>“cities[4][6]” implies that there is a maximum of 4 rows and 6 characters in each row.</p><h3>Displaying a string from a string array.</h3><pre>printf(&quot;%s&quot;, cities[0]);</pre><p>Output</p><pre>Pune</pre><h3>Quiz program using Array of Strings</h3><p><a href="https://medium.com/geekculture/functions-reusable-logic-b1fad28e72cb">We made the quiz program more simple functions here.</a> We can simplify the program, even more, using the string array.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/efc558fb628798c9d3fc25eaae9f2480/href">https://medium.com/media/efc558fb628798c9d3fc25eaae9f2480/href</a></iframe><p>Now, the program is more simplified and has no redundant codes.</p><p>It’s the end of this tutorial series. If you are a beginner or someone who would like to understand programming from different perspectives, I hope this series would have benefitted you. These are the core concepts of programming. These concepts are language-independent. If you got these concepts, it would be easy to learn new languages and new concepts like Object-Oriented-Programming.</p><p>Feedbacks are always welcome and encouraged. If you got any suggestions or feedbacks use the responses section for that.</p><p><a href="https://medium.com/geekculture/functions-reusable-logic-b1fad28e72cb"><strong>Previous =&gt; Functions — Reusable Logic</strong></a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=95621fdf85a0" width="1" height="1" alt=""><hr><p><a href="https://medium.com/geekculture/array-of-strings-95621fdf85a0">Array of Strings</a> was originally published in <a href="https://medium.com/geekculture">Geek Culture</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Functions — Reusable Logic]]></title>
            <link>https://medium.com/geekculture/functions-reusable-logic-b1fad28e72cb?source=rss-f0afe23118d2------2</link>
            <guid isPermaLink="false">https://medium.com/p/b1fad28e72cb</guid>
            <category><![CDATA[function]]></category>
            <category><![CDATA[functional-programming]]></category>
            <category><![CDATA[c-programming]]></category>
            <category><![CDATA[coding]]></category>
            <category><![CDATA[programming]]></category>
            <dc:creator><![CDATA[Shafi Sahal]]></dc:creator>
            <pubDate>Wed, 28 Jul 2021 10:33:25 GMT</pubDate>
            <atom:updated>2021-08-15T13:38:02.840Z</atom:updated>
            <content:encoded><![CDATA[<h3>Functions — Reusable Logic</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/602/1*ejRAEUg6uBU4vla3-Gvi3g.png" /></figure><p><a href="https://medium.datadriveninvestor.com/code-factory-377323ed504">Recall, the software is like a factory, where a product is produced by processing the raw materials.</a> Even though that is the big picture, the reality is that the factory itself consists of many pieces of machinery, and each of these machines takes some raw materials and processes them to produce a good. The same can be done in programming.</p><p>The whole program can be divided into functions. Each function will take an input and produce an output.</p><h3>Why Functions?</h3><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/c74862029f3ac9b4acce926d69e44eb8/href">https://medium.com/media/c74862029f3ac9b4acce926d69e44eb8/href</a></iframe><p><a href="https://medium.com/geekculture/string-an-array-of-characters-with-0-a133fd56e9d9">This is a quiz program we made in the last article.</a> You might have noticed that for each question and the answers in the quiz, about 7 lines of codes should be written. The pattern for each question is the same.</p><ol><li>Display the question</li><li>Display the options</li><li>Ask the user to enter an option</li><li>Store the input in a variable</li><li>Compare the variable and the answer</li><li>Tell the answer is correct if the variable and the answer match or wrong if it does not match.</li></ol><p>Since every question repeats the same pattern, programming this way is just redundant and redundancy is to be reduced in programming.</p><p>What we can do instead is create a function. The function takes the question, the options, and the answer as the input. It then checks whether the answer is correct and outputs if the answer is wrong or correct.</p><h3>Syntax</h3><pre>return_type function_name (arg1_type arg1_name, ...) {<br>   statements<br>}</pre><p>‘return type’ is what the function returns after processing. If the function returns an integer, the return type will be int and so on. If the function does not return anything, the return type will be void.</p><p>Arguments are the inputs the function takes. The type and the name of the argument should be given between the parentheses after the function name. If there are multiple arguments, separate the arguments by a comma.</p><p>In the curly braces, provide the code which should be executed by the function.</p><pre>int add (int a, int b) <br>{<br>   return a + b;<br>}</pre><p>This function takes two integer inputs, adds them, and returns the resulting integer.</p><h3>Calling a function</h3><p>What we have done earlier is defining the function. Defining its return type, name, arguments, and the body. When we need to use the function, we should call it. To call a function we just give the function name and put parentheses after it.</p><pre>add(5, 6);</pre><p>This statement calls the function and provides the inputs or the argument values. If the function is void, this is enough but the function above returns an integer. So, the returned integer should be stored somewhere. A variable is a good place for that.</p><pre>int sum;<br>sum = add(5, 6);</pre><p>Now, the returned integer will be stored in ‘sum’. The function takes two inputs: 5 and 6, adds them, and store the result in sum. This is a small function, so it does not make sense to make a function for adding two integers. It would be easier to just write</p><pre>sum = 5 + 6;</pre><p>The function comes in handy when there is more code or logic to be repeated. With the functions, the code should be written only once and thereafter just call the function.</p><pre>void add(int a, int b) <br>{<br>  printf(&quot;%d&quot;, a + b);<br>}</pre><p>This is how a void function is defined. See that there is no return statement.</p><pre>add(5, 6);</pre><p>The void function will be called like this and the function prints the sum of a and b on the screen.</p><h3>Built-in vs user-defined function</h3><p>The above functions are user-defined functions because we defined them. But in every programming language, there will be built-in functions which are functions made available by the language itself. We just need to call them.</p><p>The ‘printf()’ is such a built-in function. We just need to call the ‘printf()’ and provide the value to be printed as the input. This function is provided by the C language when we include the ‘iostream.h’ file.</p><p>We have seen the ‘int main() { }’, in every program we write. See that is a function. The return type is int and the name of the function is main. The main function is where the program starts execution. The main function tells the compiler: ‘<em>Hey compiler, this is the starting point for execution’. </em>The compiler keeps this in mind and marks that area as the starting point for the execution of the code. The return type of the main function is int and that is the reason for the ‘return 0;’ statement at the end of the main function. As the return type is int, we have to return some integer.</p><h3>Default value</h3><p>We can give the default value for the argument of a function. So, if there is no argument provided, the default value is set to the argument.</p><pre>int add(int a, int b = 6)<br>{<br>   return a + b;<br>}</pre><p>Argument b has a default value ‘6’. So, if the function is called ‘add(5)’, the value for b will be set as ‘6’ and the function adds 5 and 6. If there is a value provided for ‘b’, the provided value will be used.</p><h3>Quiz Program by using function</h3><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/e99f912a314367ab5a5f193259061673/href">https://medium.com/media/e99f912a314367ab5a5f193259061673/href</a></iframe><p>Here, the question, option A, option B, option C, option D, and the answer is provided to the ask function. The function after taking the input from the user and comparing the input with the answer returns 1 if the answer is correct or 0 if the answer is wrong.</p><p>See, now we do not need to write code for evaluating each question and their answer. We can just call the function and it evaluates. The code has become easier to read too. Now, if we want to change the logic in the evaluation process, we just need to change the code in the ask function.</p><p>For example, imagine we now want to award 2 points for each correct answer. Previously we have to update the ‘points++’ line to ‘points = points + 2’ on each question. With the help of the function, we just need to change the value of the points variable in the function. Just update ‘points = 1’ to ‘points = 2’.</p><p>Functions are awesome!!</p><p><a href="https://medium.com/geekculture/array-of-strings-95621fdf85a0"><strong>Next =&gt; Array of Strings</strong></a></p><p><a href="https://medium.com/geekculture/string-an-array-of-characters-with-0-a133fd56e9d9"><strong>Previous =&gt; String — An array of characters with ‘\0’</strong></a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b1fad28e72cb" width="1" height="1" alt=""><hr><p><a href="https://medium.com/geekculture/functions-reusable-logic-b1fad28e72cb">Functions — Reusable Logic</a> was originally published in <a href="https://medium.com/geekculture">Geek Culture</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[String — An array of characters with ‘\0’]]></title>
            <link>https://medium.com/geekculture/string-an-array-of-characters-with-0-a133fd56e9d9?source=rss-f0afe23118d2------2</link>
            <guid isPermaLink="false">https://medium.com/p/a133fd56e9d9</guid>
            <category><![CDATA[tutorial]]></category>
            <category><![CDATA[c-programming]]></category>
            <category><![CDATA[programming-tips]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[string]]></category>
            <dc:creator><![CDATA[Shafi Sahal]]></dc:creator>
            <pubDate>Tue, 13 Jul 2021 12:26:06 GMT</pubDate>
            <atom:updated>2021-08-09T11:07:14.823Z</atom:updated>
            <content:encoded><![CDATA[<h3>String — An array of characters with ‘\0’</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/560/1*Yf1qhJz0tWpyLLKRzzOLFQ.png" /></figure><p><a href="https://medium.com/geekculture/arrays-store-multiple-items-using-the-same-variable-7e2af6e2bdf">Numbers and characters can be stored in an array.</a> What if a word or a sentence is needed to be stored in a variable? One way to do this is using a character array. There is a more convenient way, to store them as strings.</p><h3>What is a string?</h3><p>A string is an array of characters that is terminated with a null terminator. The null terminator is a special character ‘\0’, which has the numerical value of 0. It is used to represent emptiness. So, in the case of a string, the null terminator denotes where the string ends. So, can’t we just use an empty char to terminate? No, char cannot accept empty values. It does not work like that. That is why a null terminator is used.</p><pre>char myself[] = {&#39;I&#39;, &#39; &#39;, &#39;a&#39;, &#39;m&#39;, &#39; &#39;, &#39;c&#39;, &#39;o&#39;, &#39;o&#39;, &#39;l&#39;};<br>printf(&quot;%c&quot;, myself[0]);</pre><p>Output:</p><pre>I</pre><p>This is how to store a sentence or a word using a char array. Now, think what if there is a need to display the whole sentence. The way is to create a for loop and loop through each char and display them. This is inconvenient when working with many words or when you need to compare whether two strings are equal.</p><pre>char myself[] = {&#39;I&#39;, &#39; &#39;, &#39;a&#39;, &#39;m&#39;, &#39; &#39;, &#39;c&#39;, &#39;o&#39;, &#39;o&#39;, &#39;l&#39;, &#39;\0&#39;};<br>printf(&quot;%s&quot;, myself);</pre><p>Output</p><pre>I am cool</pre><p>A string is stored like a char except for the ‘\0’ at the end. A string can be displayed using the “%s” <a href="https://medium.datadriveninvestor.com/code-factory-variables-and-data-types-aa20cfccfe80">format specifier</a>. Now, the looping of the array is not needed to display the whole sentence. This is the actual format of the strings but declaring strings is easier.</p><pre>char myself[] = &quot;I am cool&quot;;<br>printf(&quot;%s&quot;, myself);</pre><p>This too gives the same output. While declaring a string like this, the string is converted to a char array and terminated with ‘\0’ behind the scenes. So, it’s cool.</p><h3>Comparing strings</h3><p>To compare strings, we need to include ‘string.h’.</p><pre>#include &lt;string.h&gt;</pre><p>This header file provides some functions or ways to do some operations on strings. The ‘strcmp()’ is used to compare strings.</p><pre>strcmp(string1, string2);</pre><p>Within the parentheses of the ‘strcmp()’, the strings to be compared are provided. This outputs 0 if the strings are equal and some other values if the strings are not equal.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/e685d94e6e87684127fa416a5b91527a/href">https://medium.com/media/e685d94e6e87684127fa416a5b91527a/href</a></iframe><p>Output</p><pre>0</pre><h3>Assigning to a string</h3><p>String assignment does not work in the usual way.</p><pre>char myCar[] = &quot;BMW&quot;;<br>char myNewCar[] = &quot;Tesla&quot;;</pre><pre>myCar = myNewCar;<br>printf(&quot;%s&quot;, myCar);</pre><p>Output</p><pre>main.c:16:11: error: assignment to expression with array type</pre><p>The error says we are trying to assign to an expression with an array type. Basically, a string is an array of characters. So, we have to make a loop to assign each item of the myCar array to the item of myNewChar array. We cannot assign it directly. We need to use a function from ‘string.h’ that is strcpy().</p><p>To assign a string to another string pass the destination string and the source string in the order, ie strcpy(destination string, source string).</p><pre>#include &lt;stdio.h&gt;<br>#include &lt;string.h&gt;</pre><pre>int main()<br>{<br>    char myCar[] = &quot;BMW&quot;;<br>    char myNewCar[] = &quot;Tesla&quot;;<br>    strcpy(myCar, myNewCar);<br>    printf(&quot;%s&quot;, myCar);<br>}</pre><p>Output</p><pre>Tesla</pre><h3>Reading strings</h3><p>Reading string input from the user is a bit different.</p><pre>char name[30];<br>scanf(&quot;%s&quot;, name);</pre><p>Usually, an ampersand is placed before the variable to which the input value is to be stored.</p><pre>int num;<br>scanf(&quot;%d&quot;, &amp;num);</pre><p>For strings, the ampersand is not needed. The reason for this is beyond the scope of this article. You can search about it if you are interested.</p><p>This is how to read strings. It works fine for words without spaces. In sentences and full names, there will be spaces.</p><pre>char name[30];<br>printf(&quot;Enter name: &quot;);<br>scanf(&quot;%s&quot;, name);<br>printf(&quot;%s&quot;, name);</pre><p>If the name is one word like ‘Shafi’, it outputs “Shafi”. If the name contains space like “Shafi Sahal”, still the output will be “Shafi”. What happened here is that while reading the input, the reading stopped at the first occurrence of the space in the string.</p><p>To read strings with spaces, there is more than one way. Here, we will be discussing the way by using the scanset. <a href="https://www.geeksforgeeks.org/taking-string-input-space-c-3-different-methods/">You can check other ways if you are interested.</a> <a href="https://www.geeksforgeeks.org/scansets-in-c/">You may also check what is a scanset?</a></p><pre>char name[30];<br>printf(&quot;Enter name: &quot;);<br>scanf(&quot;%[^\n]&quot;, name);<br>printf(&quot;%s&quot;, name);</pre><p>Output</p><pre>Enter name: Shafi Sahal<br>Shafi Sahal</pre><p>Here, instead of a <a href="https://medium.datadriveninvestor.com/code-factory-variables-and-data-types-aa20cfccfe80">format specifier</a>, the scanset is given. The scanset tells how to read the input. The scanset is given between the square brackets: %[], in this case, the scanset is “^\n”. This tells to read the input until a newline is encountered. So, until the enter key is pressed, the whole sentence or words will be taken as the input.</p><h3>Sample Quiz Program</h3><p>Let’s make a small quiz program from all the knowledge we acquired through this and previous articles.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/c74862029f3ac9b4acce926d69e44eb8/href">https://medium.com/media/c74862029f3ac9b4acce926d69e44eb8/href</a></iframe><p><a href="https://medium.com/geekculture/arrays-store-multiple-items-using-the-same-variable-7e2af6e2bdf"><strong>Previous =&gt; Arrays — store multiple items using the same variable.</strong></a></p><p><a href="https://medium.com/geekculture/functions-reusable-logic-b1fad28e72cb"><strong>Next =&gt; Functions — Reusable Logic</strong></a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a133fd56e9d9" width="1" height="1" alt=""><hr><p><a href="https://medium.com/geekculture/string-an-array-of-characters-with-0-a133fd56e9d9">String — An array of characters with ‘\0’</a> was originally published in <a href="https://medium.com/geekculture">Geek Culture</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Arrays — store multiple items using the same variable.]]></title>
            <link>https://medium.com/geekculture/arrays-store-multiple-items-using-the-same-variable-7e2af6e2bdf?source=rss-f0afe23118d2------2</link>
            <guid isPermaLink="false">https://medium.com/p/7e2af6e2bdf</guid>
            <category><![CDATA[matrix]]></category>
            <category><![CDATA[arrays]]></category>
            <category><![CDATA[c-programming]]></category>
            <category><![CDATA[multidimensional-arrays]]></category>
            <category><![CDATA[programming]]></category>
            <dc:creator><![CDATA[Shafi Sahal]]></dc:creator>
            <pubDate>Tue, 29 Jun 2021 03:03:23 GMT</pubDate>
            <atom:updated>2021-07-13T13:57:03.784Z</atom:updated>
            <content:encoded><![CDATA[<h3>Arrays — store multiple items using the same variable.</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/647/1*9EV9gwg8GHZSw6t4Epah6w.png" /></figure><p><a href="https://medium.datadriveninvestor.com/code-factory-variables-and-data-types-aa20cfccfe80">Variables are used to store values.</a> Each variable is like a box. The box will contain a value. The box can be opened and a value can be stored in it. Then the value can be used whenever it is needed. Just open the box and take the value. It’s very useful</p><p>But imagine a scenario where the marks of five subjects should be stored. To do this, five variables can be created: subjectt1, subject2, subject3, subject4, and subject5, and the marks of each subject can be stored in it.</p><p><strong>But what if there is a need to store the names of a hundred students? </strong>Creating a hundred variables and storing values manually will very easily drive everyone crazy. Here come arrays as savior.</p><h3>Arrays</h3><p>If variables are like boxes, arrays are like lockers. Every locker in the same compartment store similar items. Each locker can be identified uniquely using the locker number. Each locker is placed sequentially in a single compartment.</p><p>Likewise, arrays are placed sequentially.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/592/1*Xymi_R77OHCanupLElO0Kg.png" /></figure><p>The indices are like the locker numbers. Indices are used to identify each array uniquely. The value of an array can be accessed with its index. From the above figure, if index 6 is accessed, the value 89 will be retrieved.</p><h3>Declaring an Array</h3><pre>int marks[5];</pre><p>Declaring array is the same as declaring variables except for the last square braces and the number in it. The square braces indicate that the particular variable is an array. The number 5 tells the computer to allocate space for storing 5 values. This number is known as the size of the array. If arrays were lockers, the number within the braces tells how many lockers are needed. Here 5 lockers will be allocated.</p><h3>Storing value in the array</h3><pre>marks[0] = 90;<br>marks[1] = 80;<br>marks[2] = 45;<br>marks[3] = 100;<br>marks[4] = 67;</pre><p>In the LHS, the index and the array, where the value should be stored are given and on the RHS, the values are given. In order to access a value just use the array name with the index. ‘marks[3]’ will give the value 100, marks[2] will give the value 45, and so on.</p><p>All the indices can be assigned together at the time of declaration like this</p><pre>int marks[] = { 90, 80, 45, 100, 67};</pre><p>Here, the size of the array do not need to be specified explicitly as the compiler will calculate it automatically form the initialization;</p><p><strong><em>Note: The indices of an array of size 5 are 0, 1, 2, 3, 4. It’s because arrays start at 0. Index 0 will be the first position of the array.</em></strong></p><p>Now, the marks can be stored using a single variable name instead of creating new names for each variable.</p><h3>Program to store and display any number of marks</h3><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/bb71326418c32faa62a65dea79d17de6/href">https://medium.com/media/bb71326418c32faa62a65dea79d17de6/href</a></iframe><p>Output</p><pre>Enter the size: 5<br>Enter mark 1: 78<br>Enter mark 2: 90.5<br>Enter mark 3: 76<br>Enter mark 4: 56<br>Enter mark 5: 73.5</pre><pre>Here goes the marks...</pre><pre>Mark 0 ----------- 78.00<br>Mark 1 ----------- 90.50<br>Mark 2 ----------- 76.00<br>Mark 3 ----------- 56.00<br>Mark 4 ----------- 73.50</pre><p>Here, two ‘for loops’ are used: one for storing the array values and the other one for displaying the values. Loops can be used to work with arrays efficiently.</p><p>These arrays are 1-dimensional. But there are 2-dimensional arrays too!</p><h3>2D Arrays</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/360/1*5hP5_WFcl4C-fk2rNkJWjQ.png" /></figure><p>2D arrays are like a 2 x 2 matrix. From the above figure, the number 14 can be accessed using [1][3]. [1] is the row index and [3] is the column index.</p><h3>Declaring a 2D Array</h3><pre>int x[3][3];</pre><p>It&#39;s the same as declaring a 1D array except for the extra index. The total number of row indices and column indices should be mentioned. Here, an array of 3 rows and 3 columns will be created.</p><p><strong><em>Note: Since arrays start at 0, the three rows will be, row 0, row 1, and row 2. The three columns will be column 0, column 1, and column 2.</em></strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/740/1*Z9rrPE1PJNS3lI0_jDuqJw.png" /></figure><p>A value at row 1 and column 2 can be accessed using x[1][2].</p><h3>Storing values in a 2D array</h3><pre>It’s simple, <br>x[0][0] = 5;<br>x[0][1] = 7; //and go on till the end<br>........<br>........<br>x[2][2] = 9;</pre><p>Values can be stored at the time of declaration like this.</p><pre>int x[3][3] = { {1, 2, 3}, {4, 5, 6}, {7, 8, 9} };</pre><p>The matrix format of the above array will be</p><pre>1 2 3<br>4 5 6<br>7 8 9</pre><p>And it does not stop with 2D, arrays can be 3D, 4D, and more. The principles for using them remain the same.</p><h3>Make a matrix using a 2D array</h3><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/c5542fb16623c242f1129ff1d49bc379/href">https://medium.com/media/c5542fb16623c242f1129ff1d49bc379/href</a></iframe><p>Output</p><pre>Enter number of rows: 3<br>Enter number of columns: 3<br>Enter the values in order:<br>1 2 3<br>4 5 6<br>7 8 9</pre><pre>Your matrix...</pre><pre>1 2 3 <br>4 5 6 <br>7 8 9</pre><p>See how a nested for loop is used to enter and display values in a 2D array. The first for loop is used for the row and the second for loop for the column.</p><p>Let’s call ‘for loop 1’ as f1 and ‘for loop 2’ as f2.</p><p>Variable ‘i’ is incremented in the f1 and variable ‘j’ is incremented in f2. Initially, i = 0 and j = 0. Then after one loop in f2, the values become i = 0 and j = 1 and it goes on in this pattern.</p><p>Nested for loops can be used to work with multidimensional arrays.</p><p><a href="https://medium.com/geekculture/repeating-logic-in-programming-4035ebf392d5"><strong>Previous article =&gt; Reapeating Logic in Programming</strong></a></p><p><a href="https://medium.com/geekculture/string-an-array-of-characters-with-0-a133fd56e9d9"><strong>Next article =&gt; String — An array of characters with ‘\0</strong></a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=7e2af6e2bdf" width="1" height="1" alt=""><hr><p><a href="https://medium.com/geekculture/arrays-store-multiple-items-using-the-same-variable-7e2af6e2bdf">Arrays — store multiple items using the same variable.</a> was originally published in <a href="https://medium.com/geekculture">Geek Culture</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>